[concurrency-interest] HTTP client libraries using NIO

Naren Chawla nchawla at bea.com
Wed Apr 13 15:51:22 EDT 2005


Anybody aware of java open-source HTTP client libraries built on top of
NIO (non-blocking IO)?

--naren


-----Original Message-----
From: concurrency-interest-bounces at cs.oswego.edu
[mailto:concurrency-interest-bounces at cs.oswego.edu] On Behalf Of Hanson
Char
Sent: Wednesday, April 06, 2005 10:01 PM
To: concurrency-interest at altair.cs.oswego.edu
Subject: [concurrency-interest]
Executors.newSingleThreadScheduledExecutor()

The javadoc of Executors.newSingleThreadScheduledExecutor():

"Creates a single-threaded executor that can schedule commands to run
after a given delay, or to execute periodically. (Note however that if
this single thread terminates due to a failure during execution prior
to shutdown, a new one will take its place if needed to execute
subsequent tasks.) Tasks are guaranteed to execute sequentially, and
no more than one task will be active at any given time. Unlike the
otherwise equivalent newScheduledThreadPool(1) the returned executor
is guaranteed not to be reconfigurable to use additional threads."

My question is if the single thread terminates due to a failure, do we
expect 

1) a new one to take its place so the periodic command will still be
re-scheduled and get executed ?   Or
2) the failure to cause a termination of the periodic execution so the
command will not be re-scheduled ?

I expect (1) but the behave of both JDK1.5_02 and the latest backport
version is (2).  Is this a bug in the code, the javadoc, or my
understanding ?

Please find below some sample test code.

Hanson

=========
Daemon.java
=========
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;


public class Daemon {
    private final ScheduledExecutorService scheduler =
        Executors.newSingleThreadScheduledExecutor();
    
    public Daemon(Runnable command, long period, TimeUnit timeUnit) {
        scheduler.scheduleAtFixedRate(command, 0, period, timeUnit);
    }
    
    public void shutdown() {
        scheduler.shutdown();
    }
}

============
DaemonTest.java
============
import java.util.Date;
import junit.framework.*;
import java.util.concurrent.TimeUnit;

public class DaemonTest extends TestCase {
	private int count;
    // if error is true, executes only once.
    // if error is false, executes every 1 sec.
    boolean error = true;

	public void test() throws InterruptedException {
		final Runnable beeper = new Runnable() {
			public void run() {
				System.out.println("run at " + new
Date());
				if (error)
					throw new
RuntimeException("test");
				count++;
			}
		};
		Daemon s = new Daemon(beeper, 1, TimeUnit.SECONDS);
		Thread.sleep(10 * 1000);
		s.shutdown();
	}
}
_______________________________________________
Concurrency-interest mailing list
Concurrency-interest at altair.cs.oswego.edu
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest





More information about the Concurrency-interest mailing list