0

I have a Thread that needs to continuously run, however when a certain action is called, I want to wait 500ms, and then do another action, without interrupting the main Thread. Is there any way to do so?

I immediately thought of creating an just restarting a new Thread each time, but this doesn't seem to work.

EDIT: There seems to be a confusion with the question, so let me elaborate. I have a thread that is contiously working. When and action is preformed, a method is called. In that method I need to wait for 500ms and then call another method, without interrupting the main thread. This also has to be re-usable.

Oliver-R
  • 23
  • 5

2 Answers2

0

This might give you the idea of how to handle similar situations:

How to Pause and Resume a Thread in Java from another Thread

Community
  • 1
  • 1
Farzan
  • 745
  • 10
  • 25
0

Quartz is an scheduler that allows you to:

... create simple or complex schedules for executing tens, hundreds, or even tens-of-thousands of jobs; jobs whose tasks are defined as standard Java components that may execute virtually anything you may program them to do. The Quartz Scheduler includes many enterprise-class features, such as support for JTA transactions and clustering.

You can implement scheduled jobs to run in a certain given time. Here you can find some tutorials and more info:

http://quartz-scheduler.org/documentation/quartz-2.1.x/tutorials/

aran
  • 10,978
  • 5
  • 39
  • 69