Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33834
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2016-02-15 17:42 -0800 |
| References | <850ed936.0406291030.3109338e@posting.google.com> <850ed936.0407011403.72a6af4c@posting.google.com> |
| Message-ID | <28ce45f7-cb0b-46e7-aeca-5b86dc6dd34b@googlegroups.com> (permalink) |
| Subject | Re: TimerTask inside Runnable? |
| From | contactkkiran@gmail.com |
On Friday, 2 July 2004 03:33:10 UTC+5:30, iksrazal wrote:
> iksrazal@terra.com.br (iksrazal) wrote in message news:<850ed936.0406291030.3109338e@posting.google.com>...
>
> This damn near killed me, but as usual the solution was simple. Thanks
> to a nice fellow over at java ranch, this is how it turned out (just
> in case someone else has the same problem someday):
>
> import java.util.*;
> import java.io.*;
>
> import EDU.oswego.cs.dl.util.concurrent.*;
>
> public class PoolTest
> {
> class TimeOutTask extends TimerTask
> {
> Thread t;
>
> TimeOutTask(Thread t)
> {
> this.t = t;
> }
>
> public void run()
> {
> if(t!= null && t.isAlive())
> {
> t.interrupt();
> }
> }
> }
>
> class MyRunnable implements Runnable
> {
> //set as true to be a daemon thread and therefore exit on
> interrupt
> Timer timer = new Timer(true);
>
> public void run()
> {
> timer.schedule(new TimeOutTask(Thread.currentThread()), 1000);
> try
> {
> System.out.println("MyRunnable...");
> Thread.sleep(10000);
> }
> catch (InterruptedException ie)
> {
> System.out.println("MyRunnable error...");
> ie.printStackTrace();
> }
> }
> }
>
> public static void main(String args[])
> {
> new PoolTest();
> }
>
> public PoolTest()
> {
> try
> {
> PooledExecutor pe = new PooledExecutor(3);
> pe.execute(new MyRunnable());
> pe.shutdownAfterProcessingCurrentlyQueuedTasks();
> }
> catch (Exception e)
> {
> e.printStackTrace();
> }
> }
> }
>
> iksrazal
Hey iksrazal this is what im looking for Excellent for posting this . You really made my day.Thanks a Tonnnnnnn. Keep it up!
Thanks,
Kiran
Back to comp.lang.java.programmer | Previous | Next | Find similar | Unroll thread
Re: TimerTask inside Runnable? contactkkiran@gmail.com - 2016-02-15 17:42 -0800
csiph-web