JRun Thread Pool Issue

I'm running CF 9.0.1 on Ubuntu on an "Medium" Amazon EC2 instance. CF has been crashing intermittently (several times per day). At such times, running top gets me this (or something similar):
PID
USER
PR
NI
VIRT
RES
SHR
S
%CPU
%MEM
TIME+COMMAND                                                                                                   
15855
wwwrun
20
0
1762m
730m
20m
S
99.3
19.4
13:22.96 coldfusion9
So, it's obviously consuming most of the server resources. The following error has been showing up in my cfserver.log in the leadup to each crash:
java.lang.RuntimeException: Request timed out waiting for an available thread to run. You may want to consider increasing the number of active threads in the thread pool.
If I run /opt/coldfusion9/bin/coldfusion status, I get:
Pg/Sec  DB/Sec  CP/Sec  Reqs  Reqs  Reqs  AvgQ   AvgReq AvgDB  Bytes  Bytes
Now Hi  Now Hi  Now Hi  Q'ed  Run'g TO'ed Time   Time   Time   In/Sec Out/Sec
0   0   0   0   -1  -1  150   25    0     0      -1352560      0      0
In the administrator, under Server Settings > Request Tuning, the setting for Maximum number of simultaneous Template requests is 25. So this makes sense so far. I could just increase the thread pool to cover these sort of load spikes. I could make it 200. (Which I did just now as a test.)
However, there's also this file /opt/coldfusion9/runtime/servers/coldfusion/SERVER-INF/jrun.xml. And some of the settings in there appear to conflict. For example, it reads:
<service class="jrunx.scheduler.SchedulerService" name="SchedulerService">
  <attribute name="bindToJNDI">true</attribute>
  <attribute name="activeHandlerThreads">25</attribute>
  <attribute name="maxHandlerThreads">1000</attribute>
  <attribute name="minHandlerThreads">20</attribute>
  <attribute name="threadWaitTimeout">180</attribute>
  <attribute name="timeout">600</attribute>
</service>
Which a) has fewer active threads (what does this mean?), and b) has a max threads that exceed the simultaneous request limit set in the admin. So, I'm not sure. Are these independent configs that need to be made to match manually? Or is the jrun.xml file supposed to be written by the CF Admin when changes are made there? Hmm. But maybe this is different because presumably the CF Scheduler should only use a subset of all available threads, right...so we'd always have some threads for real live users. We also have this in there:
<service class="jrun.servlet.http.WebService" name="WebService">
  <attribute name="port">8500</attribute>
  <attribute name="interface">*</attribute>
  <attribute name="deactivated">true</attribute>
  <attribute name="activeHandlerThreads">200</attribute>
  <attribute name="minHandlerThreads">1</attribute>
  <attribute name="maxHandlerThreads">1000</attribute>
  <attribute name="mapCheck">0</attribute>
  <attribute name="threadWaitTimeout">300</attribute>
  <attribute name="backlog">500</attribute>
  <attribute name="timeout">300</attribute>
</service>
This appears to have changed when I changed the CF Admin setting...maybe...but it's the activeHandlerThreads that matches my new maximum simulataneous requests setting...rather than the maxHandlerThreads, which again exceeds it. Finally, we have this:
<service class="jrun.servlet.jrpp.JRunProxyService" name="ProxyService">
  <attribute name="activeHandlerThreads">200</attribute>
  <attribute name="minHandlerThreads">1</attribute>
  <attribute name="maxHandlerThreads">1000</attribute>
  <attribute name="mapCheck">0</attribute>
  <attribute name="threadWaitTimeout">300</attribute>
  <attribute name="backlog">500</attribute>
  <attribute name="deactivated">false</attribute>
  <attribute name="interface">*</attribute>
  <attribute name="port">51800</attribute>
  <attribute name="timeout">300</attribute>
  <attribute name="cacheRealPath">true</attribute>
</service>
So, I'm not certain which (if any) of these I should change and what exactly the relationship is between maximum requests and maximum threads. Also, since several of these list the maxHandlerThreads as 1000, I'm wondering if I should just set the maximum simultaneous requests to 1000. There must be some upper limit that depends on available server resources...but I'm not sure what it is and I don't really want to play around with it since it's a production environment.
I'm not sure if it pertains to this issue at all, but when I run a ps aux | grep coldfusion I get the following:
wwwrun   15853  0.0  0.0   8704   760 pts/1
S
20:22   0:00 /opt/coldfusion9/runtime/bin/coldfusion9 -jar jrun.jar -autorestart -start coldfusion
wwwrun   15855  5.4 18.2 1678552 701932 pts/1  
Sl
20:22   1:38 /opt/coldfusion9/runtime/bin/coldfusion9 -jar jrun.jar -start coldfusion
There are always these two and never more than these two processes. So there does not appear to be a one-to-one relationship between processes and threads. I recall from an MX 6.1 install I maintained for many years that additional CF processes were visible in the process list. It seemed to me at the time like I had a process for each thread...so either I was wrong or something is quite different in version 9 since it's reporting 25 running requests and only showing these two processes. If a single process can have multiple threads in the background, then I'm given to wonder why I have two processes instead of one...just curious.
So, anyway, I've been experimenting while composing this post. As noted above I adjusted the maximum simulataneous requests up to 200. I was hoping this would solve my problem, but CF just crashed again (rather it slogged down and requests started timing out...so effectively "crashed"). This time, top looked similar (still consuming more than 99% of the CPU), but CF status looked different:
Pg/Sec  DB/Sec  CP/Sec  Reqs  Reqs  Reqs  AvgQ   AvgReq AvgDB  Bytes  Bytes
Now Hi  Now Hi  Now Hi  Q'ed  Run'g TO'ed Time   Time   Time   In/Sec Out/Sec
0   0   0   0   -1  -1  0     150   0     0      0      0      0      0
Obviously, since I'd increased the maximum simultaneous requests, it was allowing more requests to run simultaneously...but it was still maxing out the server resources.
Further experiments (after restarting CF) showed me that the server became unusably slogged after about 30-35 "Reqs Run'g", with all additional requests headed for an inevitible timeout:
Pg/Sec  DB/Sec  CP/Sec  Reqs  Reqs  Reqs  AvgQ   AvgReq AvgDB  Bytes  Bytes
Now Hi  Now Hi  Now Hi  Q'ed  Run'g TO'ed Time   Time   Time   In/Sec Out/Sec
0   0   0   0   -1  -1  0     33    0     0      -492   0      0      0
So, it's clear that increasing the maximum simultaneous requests has not helped. I guess what it comes down to is this: What is it having such a hard time with? Where are these spikes coming from? Bursts of traffic? On what pages? What requests are running at any given time? I guess I simply need more information to continue troubleshooting. If there are long-running requests, or other issues, I'm not seeing it in the logs (although I do have that option checked in the admin). I need to know which requests exactly are those responsible for these spikes. Any help would be much appreciated. Thanks.
~Day

I really appreciate your help. However, I haven't been able to find the JRun Thread settings you describe above.
Under Request Tuning, I see:
Server Settings > Request Tuning
Request Limits
Maximum number of simultaneous Template requests
  Restricts the number of simultaneously processed requests. Use this setting to increase overall system performance for heavy load applications. Requests beyond the specified limit are queued. On Standard Edition, you must restart ColdFusion to enable this setting. 
Maximum number of simultaneous Flash Remoting requests
  The number of Flash Remoting requests that can be processed concurrently.
Maximum number of simultaneous Web Service requests
  The number of Web Service requests that can be processed concurrently.
Maximum number of simultaneous CFC function requests
  The number of ColdFusion Component methods that can be processed concurrently via HTTP. This does not affect invocation of CFC methods from within CFML, only methods requested via an HTTP request.
Tag Limit Settings
Maximum number of simultaneous Report threads
  The maximum number of ColdFusion reports that can be processed concurrently.
Maximum number of threads available for CFTHREAD
  The maximum number of threads created by CFTHREAD that will be run concurrently. Threads created by CFTHREAD in excess of this are queued.  On Standard Edition, the maximum limit is 10. 
And under Java and JVM, I see:
Server Settings > Java and JVM
    Java and JVM settings control the way ColdFusion starts the Java Virtual Machine when it starts.  You can control settings like what classpaths are used and how memory is allocated as well as add custom command line arguments.  Changing these settings requires restarting ColdFusion.  If you enter an incorrect setting, ColdFusion may not restart properly. 
   Backups of the jvm.config file are created when you hit the submit button. You can use this backup to restore from a critical change. 
   Java Virtual Machine Path
  Specifies the location of the Java Virtual Machine.
   Minimum JVM Heap Size (MB)         Maximum JVM Heap Size  (MB)       
   The Memory Size settings determine the amount of memory that the JVM can use for programs and data. 
   ColdFusion Class Path
  Specifies any additional class paths for the JVM, with multiple directories separated by  commas.
   JVM Arguments
  -server -Dsun.io.useCanonCaches=false -XX:MaxPermSize=192m -XX:+UseParallelGC -Xbatch -Dcoldfusion.rootDir={application.home}/../ -Dcoldfusion.libPath={application.home}/../lib
  Specifies any specific JVM initialization options, separated by spaces.
I did go take a look at FusionReactor and found it's not free (which would be fine, of course, if it would actually help). It looks like there's a fully functional demo, which is cool...but I've haven't been able to get it to install yet, so we'll see.
Thanks again!
~Day
(By the way, I've cross-posted this inquiry on StackOverflow. So if you're able to help me arrive at a solution you might want to answer there as well.)

Similar Messages

  • BEA-002900 Initializing self-tuning thread pool   HANGS

    Hi All,
    Trying to start a WLS 10.3.5 instance using jrockit and it is hanging on:
    Apr 6, 2013 2:08:39 AM CDT> <Info> <WorkManager> <BEA-002900> <Initializing self-tuning thread pool>
    end of trace
    I took a thread dump and see this:
    "[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'" id=15 idx=0x3c tid=3810 prio=5 alive, waiting, native_blocked, daemon
    -- Waiting for notification on: weblogic/work/ExecuteThread@0xa0c21480[fat lock]
    at jrockit/vm/Threads.waitForNotifySignal(JLjava/lang/Object;)Z(Native Method)
    at java/lang/Object.wait(J)V(Native Method)
    at java/lang/Object.wait(Object.java:485)
    at weblogic/work/ExecuteThread.waitForRequest(ExecuteThread.java:162)
    ^-- Lock released while waiting: weblogic/work/ExecuteThread@0xa0c21480[fat lock]
    at weblogic/work/ExecuteThread.run(ExecuteThread.java:183)
    at jrockit/vm/RNI.c2java(JJJJJ)V(Native Method)
    -- end of trace
    "JFR request timer" id=16 idx=0x40 tid=3811 prio=5 alive, waiting, native_blocked, daemon
    -- Waiting for notification on: java/util/TaskQueue@0xa0c20b28[fat lock]
    at jrockit/vm/Threads.waitForNotifySignal(JLjava/lang/Object;)Z(Native Method)
    at java/lang/Object.wait(J)V(Native Method)
    at java/lang/Object.wait(Object.java:485)
    at java/util/TimerThread.mainLoop(Timer.java:483)
    ^-- Lock released while waiting: java/util/TaskQueue@0xa0c20b28[fat lock]
    at java/util/TimerThread.run(Timer.java:462)
    at jrockit/vm/RNI.c2java(JJJJJ)V(Native Method)
    -- end of trace
    ===== END OF THREAD DUMP ===============
    Done:
    1). Cleared TMP and CACHE directories and still does not solve the issue.
    Any ideas are appreciated.
    thanks

    Hi,
    we had same hang issue. Unfortunately we run behind VM.
    It was an issue with securerandom generation.
    We solved the issue as described here http://stackoverflow.com/a/2564406/2098832
    Also deleted the <server>/tmp directory before.
    Hope this helps.
    Casey

  • Pattern for Thread Pool?

    Hi
    i want to build a kind of download manager. The application should be able to handle some concurrent threads, each representing a download in progress.
    I thought i might be more efficient to reuse a download thread after the download has ended as to create a new thread each time (like the connection object for db queries). Is this right? If yes, i thought to build a thread pool that serves a limited number of threaded download objects as requested (am I on the right way?).
    Now, I have to basic problems: (a) is it right, that, if the run() method of a thread has ended, the whole thread gets destroved? if yes, how should i prevent the thread from being destroyed, so i can reuse it later on? Second (b) how would that pool mechnism look like, means, there must be some kind of vector where i put in and take out the threads.
    As you see, these are basic "pool" technique questions. So, I thought, maybe there is a design pattern that would give me the basic mechanism, Does anyone know such a pattern?
    Thanks for your help
    josh

    I thought i might be more efficient to reuse a
    download thread after the download has ended as to
    create a new thread each time (like the connection
    object for db queries). Is this right? If yes, iIt may be right, if creating new threads is wasting enough CPU cycles to justify the complication of a thread pool. Maybe for a high-load server it would be more efficient. You'll have to figure that out for your own specific application.
    Another good use for thread pools is to avoid putting time-consuming operations in ActionListeners, etc. Instead you can have them pass the task off to a thread pool, keeping the GUI responsive.
    Now, I have to basic problems: (a) is it right, that,
    if the run() method of a thread has ended, the whole
    thread gets destroved? if yes, how should i prevent
    the thread from being destroyed, so i can reuse it
    later on? Second (b) how would that pool mechnism look
    like, means, there must be some kind of vector where i
    put in and take out the threads. (a) You are right. Therefore, the worker threads should not exit their run() methods until interrupted. (b) Worker threads could check a job queue (containing Runnables, perhaps) and if there are none, they should wait() on some object. When another thread adds a new job to the queue, it should call notify() on the same object, thus waking up one of the worker threads to perform the task.
    I wrote a thread pool once, just as an exercise. You will run into a number of problems and design issues (such as, what should the worker threads do when interrupted, exit immediately or clear the job queue and then exit?) If you have any more questions, ask in this thead.
    Krum

  • Thread pool

    Hi everybody.
    How can I change the number of threads available in the thread pool in the JRE ?
    Any hint is very welcome.
    Best regards
    Susanne

    Hi.
    No, I mean some settings of the Java Runtime . In a application (byed one) I am getting the following errormessage:
    Java.lang.RuntimeException: "Request timed out waiting for an available thread. You May want to consider increasing the number of active threads in the thread pool."
    JRE is 1.4, Operation System is Solaris 8.
    How I may increase this number of active threads ? Is it an argument to java -Dsomething or is it rather an OS issue ?
    Regards
    Susanne
    Message was edited by:
    SusanneK

  • Thread Pool executor

    I run a set of java programs as a single process in solaris os. Those java programs make use of thread pool executor to process threads and it runs in an infinite loop for ever. Thread processing is done whenever data is populated in database from an external source. The issue is after 2 to 3 days of running the process, it gets slowed down in executing the threads and finally it stops executing. What may be the reason for this.....how to solve this......... or how to fine tune thread pool executor in java or how to make best use of it...........

    Hey folks.... Sorry its a typo in my e-mail. Sorry about that. I am pasting the actual code here.
    The problem again is that in the index function only FirstRunnable executes but not the SecondRunnable
    final public class Crawler {
        / create an instance of the ISSThreadPoolExecutor /
        private static ThreadPoolExecutor mythreadpoolexecutor = ThreadPoolExecutor.getInstance();
        / Constructor /
        / Index function /
        public void index( .... ) {
            :::::: code :::::::::
            // Execute this folder in a seperate thread.
            this.issthreadpoolexecutor.execute(new FirstRunnable(alpha, beta, gamma));
        / The Inner Class /
        class FirstRunnable implements Runnable {
            public FirstRunnable(int alpha, int beta, int gamma) {
            public void run() {
                            doSomething();
                            // Some other tasks and ...spawn of another thread.
                            issthreadpoolexecutor.execute(new SecondRunnable(a));
             // The Inner Class that Indexes the Folder
              class SecondRunnable implements Runnable {
                      private int ei;
                      public SecondRunnable ( int abc ) {
                            this.ei = abc;
                      public void run() {
                            doSomething ( ".....") ;
              } // End of SecondRunnable Class.
         } // End of FirstRunnable class.
    } // End of Crawler Class.

  • Thread Pool in JRT

    Hi All,
    1) the first question is what is the recommended way to allocate thread poll in rt system??
    2) what is the best way to do:
    -if my mission take a long time can i just suspend the thread and than resume it again (is it possible at all??)
    or the other option is to return it to the pool and get it again and again.
    im asking the second question from the view of performance and low latency .
    i assumed that each time i return the thread to the pool and than active it again it will "cost" cpu time.
    hope my question is clear enough.
    TIA
    Gabi

    Hi Gabi,
    I'm not completely clear on your questions. You can create a thread pool in a RT system the same basic way as in non-RT but you need to deal with priorities correctly. One way to do this would be to have the pool threads run at maximum priority normally and then drop to the actual priority of a submitted work task. Another model is to split the pool into groups based on priority, so effectively there is a work queue per priority-level and a group of threads to service each pool. This second model is used in the Real-time CORBA "lanes" approach. Designing an effective thread pool is a non-trivial task (take a look at the java.util.concurrent Thread PoolExecutor) and dealing with RT priorities and RT latency issues makes it even more complex.
    Alternatively rather than use an explicit thread pool consider whether you can convert the design to one using AsyncEvents and AsyncEventHandlers.
    Question 2 I don't really understand. Pool threads typically block on a queue waiting for work tasks to appear. But you can also have a non-terminating task that effectively picks up its own work from elsewhere - eg a task that reads from a socket to get the next "job" to process. Any interaction between threads is going to cost CPU time, whether a pool is involved or not, but yes there will be overhead associated with a pool, just as there is starting and terminating a thread, or performing any kind of thread coordination/synchronization.
    Regards,
    David Holmes

  • Thread Pool's decreasing application performance

    Hi,
    In my application, I need to make 10,000 threads for network calls at one instant and release the threads after downloading content.
    Content downloading of individual thread consumes less than 1min.
    When I try this using Timer Task and normal Threads, it works perfectly.
    But after introducing ThreadPool (initial :20,000 ; maximum: 50,000) , the response has degraded.
    Is there any limitations or known issues similar to this for thread pool's.
    Thanks!

    rock_win wrote:
    In my application, I need to make 10,000 threads for network calls at one instant and release the threads after downloading content.10000 threads all doing network connects at the same time? You better contact 10000 distinct servers and have tons of network bandwidth.
    You'll hit problems at that level long before the number of threads becomes a problem.
    Content downloading of individual thread consumes less than 1min.
    When I try this using Timer Task and normal Threads, it works perfectly.What are "normal Threads"? How many operations are you running in parallel here?
    But after introducing ThreadPool (initial :20,000 ; maximum: 50,000) , the response has degraded.You want to have 10000 Threads and declare a pool with 20000 initial threads? Why?

  • How to correctly use a fixed size thread pool?

    I am quite new to using concurrency in Java, so please forgive if this is a trivial question.
    I would like to make use of something like pool=Executors.newFixedThreadPool(n) to automatically use a fixed number of threads to process pieces of work. I understand that I can asynchronously run some Runnable by one of the threads in the threadpool using pool.execute(someRunnable).
    My problem is this: I have some fixed amount of N datastructures myDS (which are not reentrant or sharable) that get initialized at program start and which are needed by the runnables to do the work. So, what I really would like to do is that I not only reuse N threads but also N of these datastructures to do the work.
    So, lets say I want to have 10 threads, then I would want to create 10 myDS objects once and for all. Each time some work comes in, I want that work to get processed by the next free thread, using the next free datastructure. What I was wondering is if there is something in the library that lets me do the resusing of threads AND datastructures as simply as just reusing a pool of threads. Ideally, each thread would get associated with one datastructure somehow.
    Currently I use an approach where I create 10 Runnable worker objects, each with its own copy of myDS. Those worker objects get stored in an ArrayBlockingQueue of size 10. Each time some work comes in, I get the next Runner from the queue, pass it the piece of work and submit it to the thread pool.
    The tricky part is how to get the worker object back into the Queue: currently I essentially do queue.put(this) at the very end of each Runnable's run method but I am not sure if that is safe or how to do it safely.
    What are the standard patterns and library classes to use for solving this problem correctly?

    Thank you for that feedback!
    There is one issue that worries me though and I obviously do not understand it enough: as I said I hand back the Runnable to the blocking queue at the end of the Runnable.run method using queue.put(this). This is done via a static method from the main class that creates the threads and runnable objects in a main method. Originally I tried to make that method for putting back the Runnable objects serialized but that inevitably always led to a deadlock or hang condition: the method for putting back the runnable was never actually run. So I ended up doing this without serializing the put action in any way and so far it seems to work ... but is this safe?
    To reiterate: I have a static class that creates a thread pool object and a ArrayBlockingQueue queue object of runnable objects. In a loop I use queue.take() to get the next free runnable object, and pass this runnable to pool.execute. Inside the runnable, in method run, i use staticclass.putBack(this) which in turn does queue.put(therunnableigot). Can I trust that this queue.put operation, which can happen from several threads at the same time works without problem without serializing it explicitly? And why would making the staticclass.putBack method serialized cause a hang? I also tried to serialize using the queue object itself instead of the static class, by doing serialize(queue) { queue.put(therunnable) } but that also caused a hang. I have to admit that I do not understand at all why that hang occurred and if I need the serialization here or not.

  • Does SimpleDateFormat still have Thread Safety Issue in jdk 1.4.2_8?

    Hi,
    We are using jdk1.4.2_08 and experience following error message intermittently, sometimes once in 5000 or 10000 or 2/3 times in 20000 message processing.
    On one occassion, it reported as Empty String and other time it reported as ".20042005E200420054E". I won't suspect the input that's coming to this class since it works with same message over and over.
    2005-07-18 19:13:54,733 [RMI TCP Connection(6960)-10.120.102.97] INFO org.jboss.logging.util.LoggerStream write(140): java.lang.NumberFormatException: empty String
    2005-07-18 19:13:54,740 [RMI TCP Connection(6960)-10.120.102.97] INFO org.jboss.logging.util.LoggerStream write(140): at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:983)
    2005-07-18 19:13:54,745 [RMI TCP Connection(6960)-10.120.102.97] INFO org.jboss.logging.util.LoggerStream write(140): at java.lang.Double.parseDouble(Double.java:220)
    2005-07-18 19:13:54,751 [RMI TCP Connection(6960)-10.120.102.97] INFO org.jboss.logging.util.LoggerStream write(140): at java.text.DigitList.getDouble(DigitList.java:127)
    2005-07-18 19:13:54,756 [RMI TCP Connection(6960)-10.120.102.97] INFO org.jboss.logging.util.LoggerStream write(140): at java.text.DecimalFormat.parse(DecimalFormat.java:1070)
    2005-07-18 19:13:54,761 [RMI TCP Connection(6960)-10.120.102.97] INFO org.jboss.logging.util.LoggerStream write(140): at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1705)
    2005-07-18 19:13:54,767 [RMI TCP Connection(6960)-10.120.102.97] INFO org.jboss.logging.util.LoggerStream write(140): at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1156)
    2005-07-18 19:13:54,772 [RMI TCP Connection(6960)-10.120.102.97] INFO org.jboss.logging.util.LoggerStream write(140): at java.text.DateFormat.parse(DateFormat.java:333)
    It seems like some people have reported BugID 4228335 and there are few associated bugs. I assumed these are fixed in jdk1.4.
    Can anyone please suggest if this kind of issues still exist in jdk1.4.2?
    Here is the piece of code.
    private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public Object convert(Class type, Object inValue) {
    if(inValue == null)
    return null;
    NFDate ret = (NFDate) ClassDirectoryFactory.GetInstance().getClassInstance(NFDate.CLASS_KEY);
    if (inValue instanceof Date) {
    ret.setDate((Date)inValue);
    } else if (inValue instanceof String) {
    String str = inValue.toString();
    if (str != null && str.length() > 0) {
    DateFormat format = DateFormat.getDateTimeInstance();
    format.setLenient(true);
    try {
    ret.setDate(format.parse(str));
    } catch (ParseException e) {
    try {
    ret.setDate(DATE_FORMAT.parse(str));
    } catch (ParseException e1) {
    throw new DateConversionException("Unable to convert the String to NFDate. " +
    "Exception: " + e + " - expected format is (" + format.format(new Date()) + ")", e1);
    else {
    if (!ret.getIsNullDate()) ret.reset();
    } else {
    String msg = "Conversion from " + inValue.getClass().getName() + " to " + NFDate.class.getName() +
    " is not supported";
    throw new DateConversionException(msg);
    return ret;
    Thanks much in advance.
    Saikat

    It doesn't look like the format classes will ever be made thread safe. The fact that they aren't isn't a bug, it is a design choice that Sun made. If you need them to be thread safe, then you will have to do the synchronization yourself.
    If you have a finite number of threads for you application (like a thread pool) then you might consider using ThreadLocal so that separate threads will not be trying to access the same formatter.

  • 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?

  • ExecutorService thread pool shutdown exception

    Hello,
    We are developing a desktop application (no applets etc) on the Netbeans plaform. I am trying to add a thread pool via the Java5 ExecutorService. I think we have a very standard implementation using static methods - we copied it from some basic examples in blogs. Please see the class below.
    Everything seems OK until I try to run shutdown. During the application shutdown we catch an exception that says
    access denied (java.lang.RuntimePermission modifyThread)The exception is raised when running the ExecutorService "shutdown()" method.
    Please note that this is a desktop application, and we DO check the permission with the SecurityManager (see code) and we do seem to have the correct permission (no exception raised during check).
    Firstly, this is the first time we've used ExecutorService, so maybe we just have just implemented it incorrectly. Secondly, all "googling" on the issue reveals very little. It only seems to happen to applets.
    ANY SUGGESTIONS, ADVICE, GUIDANCE, HINTS would be MUCH appreciated.
    public final class ThreadPool {
        private static ExecutorService threadPool = Executors.newFixedThreadPool(3);
        public static void execute(Runnable worker) {
            threadPool.submit(worker);
        public static void shutdown() {
            SecurityManager s = System.getSecurityManager ();
            if (s!=null) {
                try {
                    s.checkPermission(new RuntimePermission("modifyThread"));
                    // we apparently have permission, so proceed to shutdown ...
                    threadPool.shutdown();  // EXCEPTION RAISED HERE !!!!!
                    threadPool.awaitTermination(15L, TimeUnit.SECONDS);
                    threadPool.shutdownNow(); // brutal mop up
                } catch (Exception e) {
                    logger.warn("ThreadPool.shutdown(): ex=" + e.getMessage());
    }

    You don't explain the context in which this application is launched - applications can be restricted by security policies too.
    shutdown requires two permissions: one from the installed SecurityManager if any, and the other directly from the AccessController. Your installed SecurityManager may be saying "yes" while the AccessController says "no". There is a change in Java 6 such that only the security manager is queried.

  • Basics of Thread Pool and MDB

    Hi,
    I am not able to connects the dots between Self-Tuning Thread Pool Threads ,number of MDB's and Open connection to Queue Manager (Listeners).
    Following is my setting
    1 Self-Tuning Thread Pool : Default i.e 5
    2) Initial Beans in Free Pool: 100
    3) Max Beans in Free Pool : 200
    What i see
    Pool Current Count :- 100 (this is as expected)
    On start up of server 105 MDB's are created (No problem with this ) (Have put static variable incrementing in constructor)
    When Messages are sent to MQ (50-100) the "Beans In Use Count" under Monitoring never shows more then 16
    and finally the "open MQ Count" on MQ Explorer is always 16.
    Questions.
    1) What do i need to change, for increasing the count of "Beans In Use Count" and "open MQ Count" on MQ Explorer to be more than 16?
    2)If the Self-Tuning thread pool is 5, how come 16 beans are executed at once? or its just that 16 are picked from pool and only 5 are executed at given time?
    NOTE:- I am using weblogic app server to connecto IBM MQ with JMS Module, so creating the customer WorkManager and attaching it to my listener (MDB) is not supported by weblogic, it says the mdb is not under webloic thread pool so this settingt will have no effect
    -thnaks

    Hi ,
    You have to create a custom work manager and then you have to associate this customer work manager to the dispatch policy of the MDB to increase the threads.
    Following links would surely help you as TomB has explained the same issue very well, do have a look at them.
    Re: WorkManager Max thread constraints not applied to MDB
    Also you can also go through this links which would help you get more information:
    Topic: Configuring Enterprise Beans in WebLogic Search for "To map an EJB to a workmanager"
    http://middlewaremagic.com/weblogic/?p=5665
    Topic: WebLogic WorkManager with EJB3 And MaxThread Constraint
    http://middlewaremagic.com/weblogic/?p=5507
    Regards,
    Ravish Mody
    http://middlewaremagic.com/weblogic/
    Come, Join Us and Experience The Magic…

  • 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.

  • A good design for a single thread pool manager using java.util.concurrent

    Hi,
    I am developing a client side project which in distinct subparts will execute some tasks in parallel.
    So, just to be logorroic, something like that:
    program\
                \--flow A\
                           \task A1
                           \task A2
                \--flow B\
                            \task B1
                            \task B2
                            \...I would like both flow A and flow B (and all their launched sub tasks) to be executed by the same thread pool, because I want to set a fixed amount of threads that my program can globally run.
    My idea would be something like:
    public class ThreadPoolManager {
        private static ExecutorService executor;
        private static final Object classLock = ThreadPoolManager.class;
         * Returns the single instance of the ExecutorService by means of
         * lazy-initialization
         * @return the single instance of ThreadPoolManager
        public static ExecutorService getExecutorService() {
            synchronized (classLock) {
                if (executor != null) {
                    return executor;
                } else {
                    // TODO: put the dimension of the FixedThreadPool in a property
                    executor = Executors.newFixedThreadPool(50);
                return executor;
         * Private constructor: deny creating a new object
        private ThreadPoolManager() {
    }The tasks I have to execute will be of type Callable, since I expect some results, so you see an ExecutorService interface above.
    The flaws with this design is that I don't prevent the use (for example) of executor.shutdownNow(), which would cause problems.
    The alternative solution I have in mind would be something like having ThreadPoolManager to be a Singleton which implements ExecutorService, implementing all the methods with Delegation to an ExecutorService object created when the ThreadPoolManager object is instantiated for the first time and returned to client:
    public class ThreadPoolManager implements ExecutorService {
        private static ThreadPoolManager pool;
        private static final Object classLock = ThreadPoolManager.class;
        private ExecutorService executor;
         * Returns the single instance of the ThreadPoolManager by means of
         * lazy-initialization
         * @return the single instance of ThreadPoolManager
        public static ExecutorService getThreadPoolManager() {
            synchronized (classLock) {
                if (pool !=null) {
                    return pool;
                } else {
                    // create the real thread pool
                    // TODO: put the dimension of the FixedThreadPool in a property
                    // file
                    pool = new ThreadPoolManager();
                    pool.executor = Executors.newFixedThreadPool(50);
                    // executor = Executors.newCachedThreadPool();
                    return pool;
         * Private constructor: deny creating a new object
        private ThreadPoolManager() {
        /* ======================================== */
        /* implement ExecutorService interface methods via delegation to executor
         * (forbidden method calls, like shutdownNow() , will be "ignored")
          // .....I hope to have expressed all the things, and hope to receive an answer that clarifies my doubts or gives me an hint for an alternative solution or an already made solution.
    ciao
    Alessio

    Two 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.

  • 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

Maybe you are looking for