Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33834 > unrolled thread
| Started by | contactkkiran@gmail.com |
|---|---|
| First post | 2016-02-15 17:42 -0800 |
| Last post | 2016-02-15 17:42 -0800 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.java.programmer
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: TimerTask inside Runnable? contactkkiran@gmail.com - 2016-02-15 17:42 -0800
| From | contactkkiran@gmail.com |
|---|---|
| Date | 2016-02-15 17:42 -0800 |
| Subject | Re: TimerTask inside Runnable? |
| Message-ID | <28ce45f7-cb0b-46e7-aeca-5b86dc6dd34b@googlegroups.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 top | Article view | comp.lang.java.programmer
csiph-web