java - ScheduledThreadPoolExecutor executeNow(); -


If a button is pressed, then how do I tell Scheduled Extra Accelerator to execute my work?

For example, if I have something like this:

  sht.scheduleAtFixedRate {New Runnabel} {@Override Public Zero () {method1 (); Method2 (); Method 3 ();}}, 0, 5, time unit MINTES);  

The methods that are within sht will be executed every 5 minutes but what I have to do is to run them "now". I can not call methods because there are some reasons.

I want something like this:

  sht.executeNow ();    

base execute () method executable Interface allows queued work for immediate execution. You should keep in the context of the scheduled Runnabel work and submit it for immediate execution on the click of a button.

If you want to reset the scheduling after clicking the button, you can do the last Runnable delete the task With the method being remodeled it is being scheduled again, in that case, the execute () method will not be required because you get an immediate execution by specifying the initial delay value of 0 in your scheduling method. You can.

Keeping your simple use in mind, you want to use Scheduled ThreadPoolExecutor instead of timer , because whatever you try There are a very simple API for it. In fact, unless you really need to run these tasks in any other threads , then you should use a handler , without the need for new ones Managing scheduling and performance threads s


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -