Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6078091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:47:39+00:00 2026-05-23T10:47:39+00:00

I have written a code in Java, something like this: …. while (conditionX) {

  • 0

I have written a code in Java, something like this:

....
while (conditionX) {
  //fetch m
  ....
  t = new Thread(new SomeRunnable(m));
  t.start();
  Thread.sleep(500);
}
....

class SomeRunnable implements Runnable {
  String msisdn;
  public SomeRunnable (String m) {
    msisdn = m;
  }
  @Override
  public void run() {
    do {
      //Statement block S uses msisdn, sets condition Y
      Thread.sleep(30000);    
    } while (conditionY);
  }
}

I am not comfortable with the number Thread.sleep()s I have used in the code. To avoid this I tried ScheduledExecutor etc, but couldn’t really figure out a way to do what I want.
I need half a second delay before a new thread is started, and in the thread, there has to be a 30s delay before the statement block S is tried again.

Please help me with a better way to code this using proper classes.
I have only provided an idea of how my code’s work flow is, if I’ve to provide more info, please let me know.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:47:40+00:00Added an answer on May 23, 2026 at 10:47 am

    You can implement a TimerTask and override run(). Then you can schedule the task periodically with:

    Timer myTimer = new Timer();
    timer.scheduleAtFixedRate(new MyTimerTask(), 500L, 30000L);
    

    When you want to cancel your task, you can do that by calling cancel()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our application, I have seen code written like this: User.java (User entity) public
I have written my own 2-3-4 tree in java. Currently, my code looks like
I have written code in Java to access web cam,and to save image... I
I have written this code to join ArrayList elements: Can it be optimized more?
I have these two snippets of code (written in Java) which is more more
I have lots of Java code written by other people and not residing in
I have written code that automatically creates CSS sprites based on the IMG tags
I have written code that opens 16 figures at once. Currently, they all open
I have written some code in my VB.NET application to send an HTML e-mail
I have written jQuery code, in files Main.html and ajax.php . The ajax.php file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.