Thread pool for Servlets
Hi all,
I am facing a big problem while doing a concurrent testing of my web application.
I am testing with 60 concurrent users.
I have set the database connection pool minimum capacity to 50, capacity increment
to 10 and maximum capacity to 100.
While there is no problem in getting database connection, the session variables
are getting mixed up (i.e. the session variable for one user is coming up as that
for another user!!!).
Does it have something to do with configuring some pool for servlets threads or
something?
Please help.
Thanks a lot in advance and best regards,
Jaya
Hi all,
I am facing a big problem while doing a concurrent testing of my web application.
I am testing with 60 concurrent users.
I have set the database connection pool minimum capacity to 50, capacity increment
to 10 and maximum capacity to 100.
While there is no problem in getting database connection, the session variables
are getting mixed up (i.e. the session variable for one user is coming up as that
for another user!!!).
Does it have something to do with configuring some pool for servlets threads or
something?
Please help.
Thanks a lot in advance and best regards,
Jaya
Similar Messages
-
Restricting Thread Pool for Servlet instances
I am using WebLogic5.1.0 version wherein I am registering a Servlet which
would be called by all the clients connecting
to my aplication. The servlet's service methods is taking some time to
execute. Since the servlet is following a SingleThreadModel, when there are
a large number of Clients connected, the number instances of Servlets
created are very high and the number of thread in the Application Server
process becomes very high affecting the performance of the other
applications.
Is it possible to restrict the number of instances of the servlets that get
created in the Application server ?
What are the setting required to achieve this ?
SandeepHi.
I'm not aware of a property setting that allows you to restrict the number of
servlet instances in WLS for the SingleThreadModel. The number of execute
threads is fixed - it does not grow depending on load. You can set this value
in the weblogic.properties file by setting weblogic.system.executeThreadCount.
This value is 15 by default.
It does sound like you are reaching the max capability of your
server/hardware. You should try tuning WLS.
Here are a couple of suggestions:
1. Try adjusting the executeThreadCount value to a higher value. Start by
setting it to 30 - see if that makes any difference.
2. Check out the following tuning guide:
http://www.weblogic.com/docs51/admindocs/tuning.html
3. Here is a list of admin properties that might aid in tuning:
http://www.weblogic.com/docs51/adminhelp/AdminPropertyHelp.html
4. If you are still having problems you might do better by posting this issue
to the performance newsgroup.
Regards,
Michael
Sandeep Rajpathak wrote:
I am using WebLogic5.1.0 version wherein I am registering a Servlet which
would be called by all the clients connecting
to my aplication. The servlet's service methods is taking some time to
execute. Since the servlet is following a SingleThreadModel, when there are
a large number of Clients connected, the number instances of Servlets
created are very high and the number of thread in the Application Server
process becomes very high affecting the performance of the other
applications.
Is it possible to restrict the number of instances of the servlets that get
created in the Application server ?
What are the setting required to achieve this ?
Sandeep--
Michael Young
Developer Relations Engineer
BEA Support -
Thread pools for execute queues
We've set up thread pools for several execute queues dedicated to high-load servlets
in our application. Once in a while, we get into a condition in which none of
these threads are available and then the threads never become available - we have
to restart the server.
I realize that this is a pretty generic description of the problem :-) but I wonder
if anyone else has encountered this and has an idea what might be causing it ?
Right now I am guessing that something in our code causes a resource contention
that eventually deadlocks all the threads. But that is just a guess.Ethan,
"Ethan Allen" <[email protected]> wrote in message
news:3e0220a1$[email protected]..
Thanks, Dimitri and Slava !
I will do this and learn a little emore ...FYI, there is a web site dedicated to weblogic documentation -
http://e-docs.bea.com/
Pick your server version, go to "Search", type "thread dump".
Regards,
Slava Imeshev
>
ethan
"Slava Imeshev" <[email protected]> wrote:
Hi Ethan,
For windows press <Ctrl>+<Break> in the server shell window,
for *nix send kill -3 {server PID}.
Regards,
Slava Imeshev
"Ethan Allen" <[email protected]> wrote in message
news:3e020fb4$[email protected]..
Thanks for your reply, Dimitri.
We have not looked at thread dumps. How may we do this ?
Ethan
"Dimitri I. Rakitine" <[email protected]> wrote:
Did you try looking at thread dumps when this happens ?
Ethan Allen <[email protected]> wrote:
We've set up thread pools for several execute queues dedicated to
high-load
servlets
in our application. Once in a while, we get into a condition in
which
none of
these threads are available and then the threads never become
available
- we have
to restart the server.
I realize that this is a pretty generic description of the problem:-) but I wonder
if anyone else has encountered this and has an idea what might be
causing
it ?
Right now I am guessing that something in our code causes a
resource
contention
that eventually deadlocks all the threads. But that is just a
guess.
>>>>
Dimitri -
Custom thread pool for Java 8 parallel stream
It seems that it is not possible to specify thread pool for Java 8 parallel stream. If that's so, the whole functionality is useless in most of the situations. The only situation I can safely use it is a small single threaded application written by one person.
In all other cases, if I can not specify the thread pool, I have to share the default pool with other parts of the application. If someone submits a task that takes a lot of time, my tasks will get stuck. Is that correct or am I overlooking something?
Imagine that someone submits slow networking operation to the fork-join pool. It's not a good idea, but it's so tempting that it will be happening. In such case, all CPU intensive tasks executed on parallel streams will wait for the networking task to finish. There is nothing you can do to defend your part of the application against such situations. Is that so?You are absolutely correct. That isn't the only problem with using the F/J framework as the parallel engine for bulk operations. Have a look http://coopsoft.com/ar/Calamity2Article.html
-
Configuration of Thread Pool for CQ's Web Container
I am trying to detrmine whether there is any specific configuration for tuning the web container thread pool for CQ. The only configuration I observe is OSGi 's Apache Sling Event Thread Pool but tuning this does not directly correlate to the thread pool that is used for serving web requests by the publish instance.
Any help would be greatly appreciated as I work through tuning our CQ instance.Unfortunately, the max thread settings is not exposed in CQ 5.5.However, all the other configurable settings (equivalent for server.xml) can be seen at [1]
[1] http://localhost:4502/system/console/configMgr/org.apache.felix.http
This is fixed in CQ 5.6 current release.
Thanks,
Varun -
Revision: 1605
Author: [email protected]
Date: 2008-05-07 14:24:53 -0700 (Wed, 07 May 2008)
Log Message:
Bug: BLZ-155 - Deadlock using a thread pool for tomcat connectors
QA: Yes - Jorge verified in the QE lab
Doc: No
Ticket Links:
http://bugs.adobe.com/jira/browse/BLZ-155
Modified Paths:
blazeds/branches/3.0.x/modules/core/src/java/flex/messaging/client/EndpointPushNotifier.j avaCross post: http://forum.java.sun.com/thread.jspa?threadID=5215686&tstart=0
If you must post across forums, just post in the most relevant one and then give the link to that in the other posts. -
Servlet Thread Pools for iPlanet WS 4.1
We have iPlanet WS 4.1 SP 5, running on HP UX. Wanted to make sure servlets run fast, so set up servlet thread pool. Initial result was that even the startup servlet could not be loaded, got stack overflow. Reduced number of threads from 60 to 5. Now startup servlet kicked off OK, but a subsequent servlet processing a request bombed with same error. This is obviously some kind of resource issue; how does one allocate enough memory or whatever it needs to handle the thread pool? Do I really even need a thread pool?
Thanks, and a follow-up question: at that reference, it seemed to imply there is really no need to allocate a user thread pool if running on Unix. Could even slow down the application. Am I likely to be OK with about 300 concurrent users if I don't allocate a thread pool? I was afraid they'd be single-threaded through the front controller servlet if I did not specifically allocate and use a thread pool, but perhaps multiple threads are already built into the container?
-
Thread pool in servlet container
Hello all,
I'm working on this webapp that has some bad response times and I've identified an area were we could shave off a considerable amount of time. The app is invoking a component that causes data to be catched for subsequently targeted apps in the environemnt. Our app does not need to wait for a response so I'd like to make this an asyncronous call. So, how best to implement this?...I considered JMS, but started working on a solution using the Java 1.4 backport of JSR 166 (java.util.concurrent).
I've been testing the use of a ThreadPoolExecutor, using an ArrayBlockingQueue. The work that each Runnable will perform involves a lot of waiting (the component we call invokes a web service, among a couple other distributed calls). So I figure the pool will be much larger than the queue. Our container has 35 execute threads, so I've been testing with a thread pool size of 25, and a queue of 10.
Any thoughts on this approach? I understand that some of this work could be simplified by JMS, but if I don't need to be tied to the container, I'd prefer not to. The code if much easier to unit test, and plays nicely with our continious build integration (which runs our junit test for us and notifies on errors).
Any thoughts are greatly appreciated...Thanks!!Well, if it works, that's by far the best way to go - but note that creating threads in a servlet container means those threads are outside of the container's control. Many containers will refuse to give the new threads access to the JNDI context, even, and some may prevent you from creating threads at all.
-
Thread ID for servlets implementing SingleThreadModel
Container creates different instances for every request to a Servlet implementing SingleThreadModel. So I tried to print thread IDs for such a Servlet by calling Thread.currentThread().getId(). I expected different thread IDs for every request to this Servlet. But what I noticed is - the same thread ID is logged several times (I got thread id 98 and 99 more than once). Can someone please explain why this is behaving like that?
If container creates a thread pool and if it assigns different requests to same thread (fetched from the pool), then what's the point in creating multiple instances of one servlet?
-
Thread pool configuration for write-behind cache store operation?
Hi,
Does Coherence have a thread pool configuration for the Coherence CacheStore operation?
Or the CacheStore implementation needs to do that?
We're using write-behind and want to use multiple threads to speed up the store operation (storeAll()...)
Thanks in advance for your help.user621063 wrote:
Hi,
Does Coherence have a thread pool configuration for the Coherence CacheStore operation?
Or the CacheStore implementation needs to do that?
We're using write-behind and want to use multiple threads to speed up the store operation (storeAll()...)
Thanks in advance for your help.Hi,
read/write-through operations are carried out on the worker thread (so if you configured a thread-pool for the service the same thread-pool will be used for the cache-store operation).
for write-behind/read-ahead operations, there is a single dedicated thread per cache above whatever thread-pool is configured, except for remove operations which are synchronous and still carried out on the worker thread (see above).
All above is of course per storage node.
Best regards,
Robert -
Cold Fusion in a generic thread pool and enabling JAVA don't mix
I've got Cold Fusion MX installed on a server running Sun One 6.1. I ran into a problem trying to enable JAVA (for servlet support) which I had previous disabled because I didn't use it.
Well, when I went to enable JAVA on the server last week, the service wouldn't restart and the error logs gave me no indication of the problem.
Through a tedious trial-and-error process I've found that having Cold Fusion running under a generic thread pool while trying to have JAVA (the j2ee plugin) running under Sun One simply doesn't work (for whatever reason).
Once I killed the pool, everything runs fine.
Does anyone happen to know why this is? I keep CFMX under its own thread pool because there are certain elements to CFMX that aren't wholly stable and can result in CFMX crashing. If it crashes, the process keeps accepting requests, but never processes them. I'd like to keep the native thread pool free to keep accepting non-CFMX requests even when CFMX crashes.
Thus the separate thread pool for CFMX.
But now I can't run CFMX in a separate thread pool with JAVA enabled.
Anyone have any insights into why this is?
ThanksTwo things. Firstly, it's better to use private static final Object classLock = new Object();because that saves you worrying about whether any other code synchronises on it. Secondly, if you do decide to go for the delegation route then java.lang.reflect.Proxy may be a good way forward.
-
The different thread pools in 6.1
Boy am I just flooded with just 6.1 migration issues. Life was much
simpler with weblogic.properties file.
Looking at Config.Dtd I couldnt see the different thread pools that WLS
5.1 offered.
How do I do set up thread pools for
a) Servlets
b) RMI
c) JMS
In 5.1 you had a servletthreadpool, an executethreadcount(for RMI) and a
jms thread pool.In 6.1
There isn't any seperate execute ThreadPool for servlets.
The only thread pool that you can tune is the default
queue which can be done via console. Ofcourse you can
configure user defined thread queues.
Also there are some internal thread pools that are not
exposed to the developers. for e.g. admin queue, replication
queue , console queue , rmi queue , jms queue etc....
If you still want to route your servlet requests via a
seperate thread queue, you have to specify
the dispatch policy & the queue name.
see below
http://e-docs.bea.com/wls/docs61/perform/AppTuning.html#1105201
Kumar
Aswin Dinakar wrote:
Boy am I just flooded with just 6.1 migration issues. Life was much
simpler with weblogic.properties file.
Looking at Config.Dtd I couldnt see the different thread pools that WLS
5.1 offered.
How do I do set up thread pools for
a) Servlets
b) RMI
c) JMS
In 5.1 you had a servletthreadpool, an executethreadcount(for RMI) and a
jms thread pool. -
Is there a code sample that takes a CORBA request and passes it to an available
thread in a thread pool. All the multi-threaded examples I have seen seem to rely
on creating a thread on receipt of a request/creation of an object, which could
be quite inefficient.
-Giles CoryEthan,
"Ethan Allen" <[email protected]> wrote in message
news:3e0220a1$[email protected]..
Thanks, Dimitri and Slava !
I will do this and learn a little emore ...FYI, there is a web site dedicated to weblogic documentation -
http://e-docs.bea.com/
Pick your server version, go to "Search", type "thread dump".
Regards,
Slava Imeshev
>
ethan
"Slava Imeshev" <[email protected]> wrote:
Hi Ethan,
For windows press <Ctrl>+<Break> in the server shell window,
for *nix send kill -3 {server PID}.
Regards,
Slava Imeshev
"Ethan Allen" <[email protected]> wrote in message
news:3e020fb4$[email protected]..
Thanks for your reply, Dimitri.
We have not looked at thread dumps. How may we do this ?
Ethan
"Dimitri I. Rakitine" <[email protected]> wrote:
Did you try looking at thread dumps when this happens ?
Ethan Allen <[email protected]> wrote:
We've set up thread pools for several execute queues dedicated to
high-load
servlets
in our application. Once in a while, we get into a condition in
which
none of
these threads are available and then the threads never become
available
- we have
to restart the server.
I realize that this is a pretty generic description of the problem:-) but I wonder
if anyone else has encountered this and has an idea what might be
causing
it ?
Right now I am guessing that something in our code causes a
resource
contention
that eventually deadlocks all the threads. But that is just a
guess.
>>>>
Dimitri -
The problem in the thread pool implemented by myself
Hello, I need to a thread pool in J2ME CDC 1.0 + FP 1.0, so I implemented a simple one by myself that also meets my own requirement.
Here is the main idea:
The thread pool creates a fixed number of threads in advance. When a task comes, it is put in the waiting list. All threads tries to get the tasks from the waiting list. If no task exists, the threads wait until someone wakes them up.
Here are the requirements from myself:
1. when a task has finished its work in one execution, it is put in the waiting list for the next run.
2. the task can control the delay between when the task owner tries to put it in the waiting list and when the task is actually put in the waiting list. I need this function because sometimes I don't want the tasks to run too often and want to save some CPU usage.
In my program, I creates two thread pools. In one pool, every task don't use the delay, and the thread pool works very well. The other pool has the tasks that use the delay, and sometimes, as I can see from the printed information, there are many tasks in the waiting list but 0 or 1 thread executes tasks. It seems that the waiting threads cannot wake up when new tasks comes.
I suspect the code in addTask(), but cannot find the reason why it fails. Could anyone please help me find out the bug in my code? I put the code of thread pool below
Thank you in advance
Zheng Da
ThreadPool.java
package j2me.concurrent;
import java.util.LinkedList;
import java.util.Timer;
import java.util.TimerTask;
import alvis.general.Util;
public class ThreadPool {
private int maxQueueSize;
private boolean running = true;
private Thread[] threads;
private LinkedList tasks = new LinkedList();
private Timer timer = new Timer(true);
private AtomicInteger usingThreads = new AtomicInteger(0);
private synchronized boolean isRunning() {
return running;
private synchronized void stopRunning() {
running = false;
private synchronized PoolTask getTask() {
while (tasks.isEmpty() && isRunning()) {
try {
this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
if (tasks.isEmpty())
return null;
// Util.log.info(Thread.currentThread().getName() +
// " gets a task, left tasks: " + tasks.size());
return (PoolTask) tasks.removeFirst();
private synchronized void addTaskNoDelay(PoolTask task) {
tasks.addLast(task);
notifyAll();
private synchronized void addTask(final PoolTask task) {
long delay = task.delay();
if (delay == 0) {
addTaskNoDelay(task);
} else {
timer.schedule(new TimerTask() {
public void run() {
addTaskNoDelay(task);
}, delay);
private synchronized int numTasks() {
return tasks.size();
private class PoolThread extends Thread {
public void run() {
Util.poolThreads.inc();
while (isRunning()) {
PoolTask task = getTask();
if (task == null) {
Util.poolThreads.dec();
return;
usingThreads.inc();
long currentTime = System.currentTimeMillis();
task.run();
long elapsedTime = System.currentTimeMillis() - currentTime;
if (elapsedTime > 100)
System.err.println(task.toString() + " takes " + ((double) elapsedTime)/1000 + "s");
usingThreads.dec();
if (!task.finish()) {
addTask(task);
Util.poolThreads.dec();
public ThreadPool(int size, int taskQueueSize) {
maxQueueSize = taskQueueSize;
threads = new Thread[size];
for (int i = 0; i < threads.length; i++) {
threads[i] = new PoolThread();
threads.start();
public synchronized boolean executor(PoolTask task) {
if (!isRunning()) {
return false;
Util.log.info("Thread Pool gets " + task + ", there are "
+ numTasks() + " waiting tasks");
if (numTasks() >= maxQueueSize) {
return false;
addTask(task);
return true;
public synchronized void destroy() {
stopRunning();
timer.cancel();
// TODO: I am not sure it can wake up all threads and destroy them.
this.notifyAll();
public synchronized void printSnapshot() {
System.err.println("using threads: " + usingThreads + ", remaining tasks: " + tasks.size());
PoolTask.javapackage j2me.concurrent;
public interface PoolTask extends Runnable {
* It shows if the task has already finished.
* If it isn't, the task will be put in the thread pool for the next execution.
* @return
boolean finish();
* It shows the delay in milliseconds that the task is put in the thread pool.
* @return
long delay();are receiving/sends tasks packets time consuming operation in your case or not? if it is not you do not need to use thread pools at all. you can create a queue like in your code through the linked list and dispatch this queue periodically with minimum monitor usage. try this.
import java.util.LinkedList;
public class PacketDispatcher extends Thread {
LinkedList list = new LinkedList();
public PacketDispatcher (String name) {
super(name);
public void putTask(Task task) {
synchronized (list) {
list
.add(task);
list.notify();
public void run() {
while (true/* your condition */) {
Task task = null;
synchronized (list) {
while (list.isEmpty())
try {
list.wait();
} catch (InterruptedException e) {
e.printStackTrace();
task = (Task)list
.poll();
if (task == null) {
try {
Thread
.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
continue;
task
.run();
if (!task.isFinished()) {
putTask(task);
Thread
.yield();
public static void main(String[] args) {
// just for test
try {
Thread.sleep (10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
PacketDispatcher dispatcher = new PacketDispatcher("Packet Dispatcher");
Task task = new Task();
dispatcher.putTask(task);
dispatcher.start();
try {
Thread.sleep (10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Task task2 = new Task();
dispatcher.putTask(task2);
class Task {
long result = 0;
public boolean isFinished () {
if (getResult() >= 10000000) {
return true;
return false;
public void run() {
for (int i = 0; i < 1000; i++) {
result += i;
public long getResult () {
return result;
} -
Fixed Size Thread Pool which infinitely serve task submitted to it
Hi,
I want to create a fixed size thread pool say of size 100 and i will submit around 200 task to it.
Now i want it to serve them infinitely i.e once all tasks are completed re-do them again and again.
public void start(Vector<String> addresses)
//Create a Runnable object of each address in "addresses"
Vector<FindAgentRunnable> runnables = new Vector<FindAgentRunnable>(1,1);
for (String address : addresses)
runnables.addElement(new FindAgentRunnable(address));
//Create a thread pool of size 100
ExecutorService pool = Executors.newFixedThreadPool(100);
//Here i added all the runnables to the thread pool
for(FindAgentRunnable runnable : runnables)
pool.submit(runnable);
pool.shutdown();
}Now i wants that this thread pool execute the task infinitely i.e once all the tasks are done then restart all the tasks again.
I have also tried to add then again and again but it throws a java.util.concurrent.RejectedExecutionException
public void start(Vector<String> addresses)
//Create a Runnable object of each address in "addresses"
Vector<FindAgentRunnable> runnables = new Vector<FindAgentRunnable>(1,1);
for (String address : addresses)
runnables.addElement(new FindAgentRunnable(address));
//Create a thread pool of size 100
ExecutorService pool = Executors.newFixedThreadPool(100);
for(;;)
for(FindAgentRunnable runnable : runnables)
pool.submit(runnable);
pool.shutdown();
try
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
catch (InterruptedException ex)
Logger.getLogger(AgentFinder.class.getName()).log(Level.SEVERE, null, ex);
}Can anybody help me to solve this problem?
Thnx in advance.Ravi_Gupta wrote:
*@ kajbj*
so what should i do?
can you suggest me a solution?Consider this thread "closed". Continue to post in your other thread. I, and all others don't want to give answers that already have been given.
Maybe you are looking for
-
I've had some strange browser issues, with Conduit being added to Chrome (which I've tried to remove via the browser settings). Chrome will open my Gmail account but no ther pages. Firefox won't open anything. Safari opens a few pages (this forum tha
-
Traded in my iPhone for a different brand of phone. I had no idea that I had to sign out of iMessage before doing this. Now, my old phone is gone and my new phone cannot receive texts from people who have iphones and had me as a contact before. They
-
Can't copy and paste from windows to firefox(apple)
I have an apple(mac os x). I have parallels desktop 3.0 for this mac. Problem: can't copy and paste from windows to firefox.
-
How to improve the updating a sql server table with another table in Oracle
Hi there. I am trying to do the next updating in SSIS UPDATE S SET S.COLUMN_A = OT.COLUMN_A, S.COLUMN_B = OT.COLUMN_B FROM SQLT1 S INNER JOIN ORACLET1 OT ON S. COLUMN_C = OT.COLUMN_C This is what I am doing: I am taking the Oracle data with the ODB
-
Camera Raw Color Distortion?
I'm new to Photoshop. Currently, Im learning Photoshop through Adobe Photoshop CS6 Classroom in a Book. I found out that the camera raw plug-in seems weird. This is the original photo. When I opened it in Camera Raw, the color of the photo distorted.