The Artima Developer Community
Sponsored Link

Java Answers Forum
ThreadPoolExecutor and ArrayBlockingQueue

1 reply on 1 page. Most recent reply: Jul 19, 2005 8:22 PM by Chad Gorshing

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Chad Gorshing

Posts: 12
Nickname: gorshing
Registered: Jun, 2004

ThreadPoolExecutor and ArrayBlockingQueue Posted: Jul 6, 2005 12:30 PM
Reply to this message Reply
Advertisement
I must be missing something about ThreadPoolExecutor and/or ArrayBlockingQueue. Running the code below I get the following result:

starting up testThreadPool2$1@de6ced
run() : 7
run() : 7


I am not understanding why it seems to run twice, could anybody shed some light on this for me?


import java.util.concurrent.*;

public class testThreadPool
{
public static void main( String [] args )
{
ArrayBlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>( 20 );

ThreadPoolExecutor tester = new ThreadPoolExecutor( 5, 20, 1, TimeUnit.SECONDS, workQueue );

workQueue.add( new Runnable() {

public void run()
{
System.out.println( "run() : " + Thread.currentThread().getId() );
System.out.flush();
}
} );

for( Runnable r : workQueue )
{
System.out.println( "starting up " + r.toString() );
tester.execute( r );
}
}
}


Chad Gorshing

Posts: 12
Nickname: gorshing
Registered: Jun, 2004

Re: ThreadPoolExecutor and ArrayBlockingQueue Posted: Jul 19, 2005 8:22 PM
Reply to this message Reply
Adding the Runnable objects to the queue does not work as I expected it to. The currect method to use is ThreadPoolExecutor.submit

Flat View: This topic has 1 reply on 1 page
Topic: Thread,  Vector, Inheritance Problem Previous Topic   Next Topic Topic: Japanese text validation

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use