FileDocCategorySizeDatePackage
MultithreadedExample.javaAPI DocExample2911Wed May 18 09:39:00 BST 2005com.discursive.jccook.httpclient

MultithreadedExample

public class MultithreadedExample extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

		MultithreadedExample example = new MultithreadedExample();
		example.start();
	
public voidstart()

		HttpConnectionManager connectionManager = 
					new MultiThreadedHttpConnectionManager();
					
		HttpConnectionManagerParams params = connectionManager.getParams();
		params.setIntParameter( HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, 2 );
		params.setIntParameter( HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 4 );

		List retrievers = new ArrayList();

		for( int i = 0; i < 20; i++ ) {
			HttpClient client = new HttpClient(connectionManager);
			Thread thread = new Thread( new PageRetriever(client) );
			retrievers.add( thread );
		}
		
		Iterator threadIter = retrievers.iterator();
		while( threadIter.hasNext() ) {
			Thread thread = (Thread) threadIter.next();
			thread.start();
		}