0

I have a program, in there I have this thread which will recieve Strings from another user and save them in another object. I want to make this thread run the "seek for Strings and save them-method" every x seconds. How do I do that?

2 Answers2

2

I believe this answer would be helpful to you: https://stackoverflow.com/a/12908477/3328790

The user suggests you use Timer and TimerTask classes which you can use to schedule your task to run every n seconds.

Community
  • 1
  • 1
  • As commented above, using a `java.util.concurrent.ScheduledExecutorService` is a much better solution than a `Timer`/`TimerTask` arrangement. – dcsohl Feb 20 '14 at 16:53
0

Create a Runnable which would be used in your periodically running Thread and create another Runnable which will start the needed Thread in conform of your needs. Start the second Thread.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175