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

  • Home
  • SEARCH
  • 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 8488359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:30:46+00:00 2026-06-10T21:30:46+00:00

Class A { long x; method1() { x = current time in millisecs; }

  • 0
Class A 
{
 long x;
 method1()
  {
   x = current time in millisecs;
  }
 task()//want to run this after (x+30) time
}

I need to run task() after (x+30) . x could be varying. if method1 is called, then task is scheduled to run after 30 from current time, but within that 30 timeperiod if method1 is called again then i want to cancel the previous task call and want to schedule a new call to task after 30 sec from current time. How should i create a scheduler or task of this type?

Went through the scheduledthreadpoolexecutor API but didn’t find a scheduler of this type.

  • 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-06-10T21:30:47+00:00Added an answer on June 10, 2026 at 9:30 pm

    You’re asking 2 questions:

    1. How can I schedule a task with an arbitrary delay?

    You can use one of the schedule methods on a java.util.concurrent.ScheduledThreadPoolExecutor

    int delay = System.currentTimeMillis + 30;
    myScheduledExecutor.schedule(myTask, delay, TimeUnit.MILLISECONDS);
    

    2. How can I cancel an already running task?

    You cancel a task by calling cancel on the Future that is returned from the schedule method you called.

    if (!future.isDone()){
        future.cancel(true);
    }
    future = myScheduledExecutor.schedule(myTask, delay, TimeUnit.MILLISECONDS);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a class like this: class Owner { private: long m_Id; QString
If I have this entity: @Entity class Pet { @Id long id; public enum
I have a public method called LoadContact() in the Contact class. I want to
This is my current code of the class Score in the Score.h file:- class
I have been trying to play around with this for a long time and
Long term lurker, first time poster here. I have written a class to model
I am looking for a class or method that takes a long string of
To avoid the long class path issue in windows, i modified my build.xml like[1]
i have a class like: class myclass{ Long id; String a; Text b; }
I have a class cl1: class c1 { long double * coords; ... }

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.