Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Is Executor class thread-safe

Reply
Thread Tools

Is Executor class thread-safe

 
 
Rakesh
Guest
Posts: n/a
 
      10-12-2008
I am working on a tree traversal algorithm ( reduced form of the main
problem ) - such that we need to figure out the different paths from
the root of the tree to the leaves of the same.

Assuming a BFS algorithm to begin with - I was thinking along the
following lines..

1) Initialize a global blockingQueue..
2) For each child
spawn a new thread for each child.
add child to the current path ..
repeat the algorithm until leaf is reached.
3) If node is a leaf - consolidate the list of nodes visited
(accumulated throughout the thread).
Put it in the blockingQueue to indicate the result.


For each and every step - whenever I need to spawn a new thread , I
wanted to do it under the control of an executor such that -
executor.executor(runnable).

My Q is - (as per the algo above) - clearly multiple threads would be
using the same executor to launch new sub threads. Is the executor
thread-safe with multiple threads calling execute method (with
different instances of Runnable ) of the same Executor reference.
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      10-13-2008
Rakesh wrote:
> I am working on a tree traversal algorithm ( reduced form of the main
> problem ) - such that we need to figure out the different paths from
> the root of the tree to the leaves of the same.
>
> Assuming a BFS algorithm to begin with - I was thinking along the
> following lines..
>
> 1) Initialize a global blockingQueue..
> 2) For each child
> spawn a new thread for each child.
> add child to the current path ..
> repeat the algorithm until leaf is reached.
> 3) If node is a leaf - consolidate the list of nodes visited
> (accumulated throughout the thread).
> Put it in the blockingQueue to indicate the result.
>
>
> For each and every step - whenever I need to spawn a new thread , I
> wanted to do it under the control of an executor such that -
> executor.executor(runnable).
>
> My Q is - (as per the algo above) - clearly multiple threads would be
> using the same executor to launch new sub threads. Is the executor
> thread-safe with multiple threads calling execute method (with
> different instances of Runnable ) of the same Executor reference.


I think the answer to your question is yes but that's because I think I
know what you are asking . You don't know what thread may be used to
run your task, it could be the calling thread, a thread in a pool or a
new thread. In any case calling execute() from different threads should
not cause any problem. The blocking queues are thread safe as well.

--

Knute Johnson
email s/nospam/knute2008/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
An Executor-like structure providing more than threads Tom Anderson Java 12 01-21-2010 11:51 PM
Parallel processing using Executor? howa Java 8 08-15-2007 10:37 AM
Looking for Program Executor class in java Prafulla T Java 5 02-07-2007 07:05 PM
Executor Kenneth P. Turvey Java 8 09-20-2005 08:33 PM
Cancelling an Executor thread iksrazal Java 0 06-21-2004 10:19 PM



Advertisments