?
Solved

how to write a thread that ends after 10 seconds

Posted on 2007-08-09
1
Medium Priority
?
192 Views
Last Modified: 2013-11-05
Ok, let's say i have a class that implements Runnable and I have the method public void run().  In the run method, I have a loop that runs a process.  Now, I need this process to run exactly 10 seconds and stop.  how can i add the timer to this?
0
Comment
Question by:tbboyett
1 Comment
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 19661681
can't really use a timer for that. you ned to stop the thread from within your run() method.
For example periodically checking elapsed time (say each loop iteration) and exit once > 10 seconds.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question