0

As a part of my project i need to create a threadpool containing fixed no of threads.when ever the threads are allocated to different processes , i need to allocate that many sessions too along with the threads.I want to use a ConcurrentLinkedQueue(of fixed size) to store the sessions so that as and when the threads are done ,i can put back my sessions into the Queue ,making it available to other processes.Hope my requirement is been made clear...Can any one give me some quidelines as of how this can be implemented..?how a ConcurrentLinkedQueue can be used..?

1
  • Are you talking about "processes" within your program or multiple processes as the OS would understand them? Commented Feb 28, 2011 at 12:28

2 Answers 2

1

I assume you want to do the same thing as

Executors.newFixedThreadPool(n);

It not clear why you don't just use this thread pool.

It appears also you want to use a Queue as an object pool. You can use add() to and poll() to see if a free element is available.

Sign up to request clarification or add additional context in comments.

Comments

0

when ever the threads are allocated to different processes ...

You won't be able to share resources between threads in different processes with a ConcurrentLinkedQueue. It will be only accessible from the threads of one process.

If this is not the problem you can use a thread pool:

Executors.newFixedThreadPool(int nThreads, ThreadFactory threadFactory) 

A ThreadFactory can associate the Session resource with the threads managed by the thread pool using a ThreadLocal. You can configure different initialization strategies. Don't forget to clean up the sessions when the thread pool shuts down.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.