X-Received: by 10.66.221.201 with SMTP id qg9mr257664pac.10.1361894955531; Tue, 26 Feb 2013 08:09:15 -0800 (PST) X-Received: by 10.50.100.167 with SMTP id ez7mr1675186igb.16.1361894955330; Tue, 26 Feb 2013 08:09:15 -0800 (PST) Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!news.glorb.com!jn4no8954097pbb.1!news-out.google.com!ov8ni17067pbb.1!nntp.google.com!su1no9452081pbb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Tue, 26 Feb 2013 08:09:14 -0800 (PST) In-Reply-To: <5w697krlf571$.1hwa9p5it81zl.dlg@40tude.net> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=137.100.97.30; posting-account=LYoTOgoAAABkuGLLOGXg_LiQpwWAp52F NNTP-Posting-Host: 137.100.97.30 References: <7024d5a0-10c2-41db-bd72-85d03c3feae6@googlegroups.com> <5w697krlf571$.1hwa9p5it81zl.dlg@40tude.net> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <55b9dfa9-2e79-4e42-b5fb-de6a44db9188@googlegroups.com> Subject: Re: Concurrency and restarting tasks From: me 2 Injection-Date: Tue, 26 Feb 2013 16:09:15 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: csiph.com comp.lang.java.programmer:22536 On Tuesday, February 26, 2013 9:58:28 AM UTC-5, Joerg Meier wrote: > On Tue, 26 Feb 2013 06:32:28 -0800 (PST), me 2 wrote: >=20 >=20 >=20 > > I have an interesting (to me at least!) puzzle. >=20 >=20 >=20 > > I have a task that can take a long time that I need to run periodically= . I want to be able to cancel the execution of that task. I've been looki= ng at the Scheduler and Future objects, but I haven't seen how to cleanly s= top, wait for a couple of seconds and restart the task on schedule. And my= task won't always take X seconds--sometimes it will generate exceptions or= take longer or shorter or any number of other things. >=20 >=20 >=20 > > There are plenty of examples that show the first steps--setting up the = schedule and canceling. Restarting apparently is not as common. >=20 >=20 >=20 > As I understand, ThreadS are simply not made to be resumed after being >=20 > cancelled. What you want might simply not be possible. That being said, i= t >=20 > shouldn't be too hard to simply make a new Thread with your Runnable and >=20 > start that instead of restarting the cancelled one. >=20 >=20 >=20 > Alternatively, you can make your long running task somehow check for a >=20 > volatile flag and pause if it's set to something. >=20 >=20 >=20 > Liebe Gruesse, >=20 > Joerg >=20 >=20 >=20 > --=20 >=20 > Ich lese meine Emails nicht, replies to Email bleiben also leider >=20 > ungelesen. Hey, I suppose you are right. That doesn't make much sense when you put it like= that. The problem is that I need an event to fire if the task doesn't complete in= X seconds. I guess I don't really care about canceling the thread--just g= etting the event to fire and then getting set up to attempt the task again. The double setup with the two scheduled tasks--one to start and one to canc= el--gets muddled after like the 4th iteration. Hmmm.... I'll keep looking. Me