ScheduledThreadPoolExecutor core thread pool / keepalive/timing out threads

Hi,
I am using a ScheduledThreadPoolExecutor - java1.6 on Windows(currently).
I would like to minimise the number of threads in the pool running at any one time to around the number of threads required to run the number of tasks that are concurrently executing.
However, I don't seem to be able to get the thread pool to minimise the number of threads below the max threads in the constructor.
I want to do this mainly because I have a large delay queue and the performance of the pool seems to be better when the number of threads in the pool is minimised to roughly the number of threads required to service the concurrently executing tasks.
Any ideas?
Thanks,
Alex
                ThreadFactory tf = new MyThreadFactory();
          ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(50,tf);
          scheduler.setCorePoolSize(10);
          //scheduler.setMaximumPoolSize(50);
          scheduler.setKeepAliveTime(1, TimeUnit.NANOSECONDS);
          scheduler.allowCoreThreadTimeOut(true);
          scheduler.schedule(aTask, 10, TimeUnit.SECONDS);
...

because of how a scheduledthreadpoolexecutor works, it doesn't really make sense to have a variable number of threads. since threads are only added when tasks are added to the pool (aka, when submit is called), once the core threads timed out they would never get replaced (e.g. you would eventually get down to 1 thread and never get anymore added). one way to achieve what you want would be to have a single threaded ScheduledThreadPoolExecutor, where the scheduled jobs do the real work in a separate, variable size thread pool (e.g. the scheduled tasks do not do anything but submit a task to the real work thread pool). this solution would work fine for "schedule at fixed rate" but not for "schedule with fixed delay". you would actually have to simulate the latter by scheduling a one-off task which resubmits itself to the scheduler each time it completes.

Similar Messages

  • Cisco CDN (Alarm 550001 (SEKeepalive) SE keepalive timed-out )

    Dear Cisco Experts,
    My systems as below:
    CDSM, SR: version 3.2.1
    SE1: version 3.2.1
    SE2: version 2.6.3
    Status (all devices): online (from CDSM: cms connectivity from all devices are OK)
    SE1 can work normally, but SE2 doesn't work, Alarm:"SE SE2 keepalive timed-out" from CDSM.
    log from SR:
    192.168.11.0/24 20 SE2 (Down, Static)
    192.168.8.0/24 20 SE1 (Operational, Static) (Load 1%, Device Threshold not reached)
    0.0.0.0/0 10 SE1 (Operational, Static) (Load 1%, Device Threshold not reached)
    0.0.0.0/0 10 SE2 (Down, Static)
    I found infor from cisco about this alarm:
    Alarm 550001 (SEKeepalive) SE keepalive timed-out or SE is not reachable.
    Explanation    Either the SR has not received keepalives from the SE, or the SE is not reachable.
    Recommended Action    Check the cables connected to the network device and the SE.
    I'm sure about network connectivy is OK, problem should be from Version mismatch between SE and SR, Could you help me for this?
    Many thanks and rgds.

    Hi Long,
    The alarm message that you are querying is indicating the keepalive between SR and SE has timed out.
    There is UDP based keepalive messages sent from each SE to all SR periodically, by default it is 2 seconds. It is configurable via CDSM GUI. The destination port is 2323. This message has SE load information inside.
    To check the keepalive message, you can execute following command on SR
    SR# tcpdump udp port 2323
    To debug keepalive, you can enable
    SR#debug service-router keepalive
    Then check service router errorlog under /local1
    SR#type-tail errorlog/service_monitor_errorlog.current follow
    check any error message popup. quit by Ctrl+C, then undebug all
    SR#undebug all
    Between 2.6.3 and 3.2.1, there is major difference in the format of packet. We do not recommend you to mix the version in production network. If you are requesting urgent assistance because of the service impact by this alarm, please do contact Cisco TAC support.
    Best Regards,
    Richard Xie

  • Request threads not timing-out

    I am connecting to the crystal report server(11.5) using RAS APIs from my web application hosted on Websphere 6.
    It seems the threads are not timing out, below are the threads:
    com.crystaldecisions.thirdparty.com.ooc.OB.GIOPClientWorkerThreaded$SenderThread                                                               
    com.crystaldecisions.thirdparty.com.ooc.OB.GIOPClientWorkerThreaded$ReceiverThread      
    com.crystaldecisions.thirdparty.com.ooc.OB.GIOPServerStarterThreaded$StarterThread                                                             
    com.crystaldecisions.thirdparty.com.ooc.OB.GIOPClientWorkerThreaded$SenderThread                                                               
    com.crystaldecisions.thirdparty.com.ooc.OB.GIOPClientWorkerThreaded$ReceiverThread     
    I tried putting clientSDKOptions.xml in my web application but it doesn't seem to be working.
    Any inputs to this will be helpful.

    I'd give more details concerning the clientSDKOptions.xml.
    Sincerely,
    Ted Ueda

  • Thread pool tuning on J2ee NW04s...

    Hi,
    I have troubles in defining the number of threads in the pool of the server and dispatcher.
    First of all, I know that there are several thread pools depending on the node you are:
      - Server node: System and Application thread pool.
      - Dispatcher: System thread pool.
    I know that application pool is dedicated to client requests that come in and system is for the services, libs and core of the nodes.
    I'd like to know if I set to a server node a certain number of threads for the System and Application pool, what would be the value of the System thread pool of the dispatcher?
    As almost everything is going through the dispatcher before to reach the server node, what would be the number of System threads of the dispatcher if there are two or three server nodes? Should I multiply the number current threads of the dispatcher by the number of server nodes?
    If there are a lot of P4 calls (each call needs System 2 threads, one for the request and one for the response) should I deduce the number of thread of the dispatcher using this formula if there is one server node in the worse case:
    Dispatcher System Threads = Server App Threads + (Server System Threads x 2)
    Thanks in advance,
    Serge.

    Hi Serge,
    One way that you can size the number of threads is by using the monitoring stats in the VA.  VA -> cluster -> dispatcher/server -> services -> monitoring -> Runtime (tab) -> Monitor Tree (tab)
    then Root -> Kernel
    Check the Application Threads Pool and System Threads Pool. 
    As long as you DON'T experience CPU bottlenecking, then you can increase the number of threads, if:
    1) The ActiveThreadsCount is always at the MaximumThreadPoolSize
    2) You are noticing the WaitingTasksCount is always high.
    If you are experiencing CPU bottlenecking then increasing the number of threads is useless.
    Regards
    Anthony

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

  • JMS Thread Pool Size

    Hi,
              I'm using WLS 6.1. The console has a setting for: JMS Thread Pool Size. I wanted to tune the number of threads used by JMS. I thought JMS asynch consumers would use threads in this pool however that doesn't seem to be the case (they all use the default execute threads and queues). Why is this setting available?
              Note the BEA WebLogic JMS Performance Guide talks about tuning this value from version 6.1 up to 8.1 and states "On the server, incoming JMS related requests execute in the JMS execute queue/thread pool."
              Thanks in advance for any responses,
              Mich

    Disregarding what it is for, in my experience, tuning this setting rarely has much effect. For 6.1, the main thread pool related tunables to look at are the EJB thread pools and EJB max-beans... settings, the "default" thread pool, and the internal thread-pool for stand-alone clients -- all of which are mentioned in the performance guide.

  • Servlet thread pool

    Is there any way I can create my own init() for the threads in the servlet thread pool (by overriding some method or through other means)? (Not to be confused with the servlet's init().)

    web server itself is a thread pool implementation, unlesss your thread has other purpose, if not it is suited and enough for you do not implement another thread for it. If you want some init method, you can call from other class before start of your thread pooling.
    Hopefully can help you...

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

  • Setting Thread pool size

              Hi,
              I want to know if I set a system property "-Dweblogic.ThreadPoolSize", how will the
              WLS get to know that the pool size has been changed, at run time?
              E.g. I pass -Dweblogic.ThreadPoolSize=30 from the command-line. Then if I change
              the pool size to 40 at runtime, is there any event that I can fire for the change
              in property through APIs?
              Thnx in advance.
              Best Regards
              Ali
              

    Disregarding what it is for, in my experience, tuning this setting rarely has much effect. For 6.1, the main thread pool related tunables to look at are the EJB thread pools and EJB max-beans... settings, the "default" thread pool, and the internal thread-pool for stand-alone clients -- all of which are mentioned in the performance guide.

  • Application Server Session timed out (-11) (lack of debug in internal ITS)

    Dear Sirs,
    I get the error message below, when I try to run a IAC through internal ITS. The IAC worked for a while (<30 minutes), and then suddenly this error appeared.
    I can see that this error message has been asked about previously, but then in connection with statefull/stateless BSP applications (e.g "Session timed out thread", on this forum May 31 2005).
    In this thread the solution is apparently to alter the 'rdisp/plugin_auto_logout', is this the case for us as well?
    I have read Error handling using the ICM , but not able to actually beeing able to pinpoint the problme.
    All our other IAC are working it is only a problem with one of them. The problem is still valid even if I log on with different user, and the error is still there now even after two hours. The problem transaction is a altered version of the WSTA, and I am able to get the first screen where I enter the store number. 
    Any tips or suggestions to pinpoint the error?
    +400 Session timed out - please log in again
    Application Server Session timed out (-11)
    Error:     -11
    Version:     6040
    Component:     ICM
    Date/Time:     Thu Apr 27 14:13:56 2006
    Module:     icxxthr_mt.c
    Line:     1719
    Server:     xxXXXt_TXX_XX
    Detail:     Session does not exist+
    In SM21 :
    +Transaction Canceled ITS_P 025 ( 0x2103: Interpreter: The input contains errors. )                                                              
    Documentation for system log message D01 :
    The transaction has been terminated.  This may be caused by a termination message from the application (MESSAGE Axxx) or by an error detected by the SAP System due to which it makes no sense to proceed with the transaction.  The actual reason for the termination is indicated by the T200 message and the parameters.                         
    Additional documentation for message ITS_P               025 Template interpretation terminated - internal error &1                        
    No documentation exists for message IT025+                                     
    Best regards,
    Jørgen

    Dear Sirs,
    The error has been solved. It was a matter of an illegal input sendt to the RetailHeaderFunction.
    However, this makes way for another question.
    On the standalone ITS, it was possible to get error messages which indicated where the code contained errors, when it was runned.
    How is it possible to make the internal ITS gives better feedback (errors?), and show where the error is?
    Jørgen

  • IChat login/timing out. . . .Only on one account

    Ok so i turn on my computer this morning and it times out when ever i try to login to aim using ichat. i though it might because i had i updated ichax last week so i uninstalled ichax and still it times out so then i signed using another aim account and it worked with no probelm. deleted all accounts and then tried my account info again but it still timed out. i also tried switching the ports
    i am running 10.4.6
    ichat v. 3.1.4
    i looked at a bunch of threads involving ichat timing out but nothing seemed to anwser is prob thanks

    Hi Rick,
    I am aware that you are posting in serveral threads with an issue you have.
    I am unable to gauge what the exact issue is with this fragmented approach.
    Could you start your own thread and list what the problem is is as much detial as you have and what you have tried please
    This item may help
    http://discussions.apple.com/thread.jspa?threadID=527902
    1:41 PM Wednesday; August 2, 2006

  • Out Of Memory Exception with Thread Pool

    Hi,
    I'm using the ThreadPooling, and I have a problem. In my usage, I submit a bunch of tasks to my application, and i have a pool of THREADS, so while executing these tasks i am getting the following errot :
    Exception in thread "pool-1-thread-271" java.lang.OutOfMemoryError: Java heap space
    I am not able to understand, what could be the reason to get this error, please help me
    any one who knows it .

    a few things to consider
    1. increasing the heap size
    2. you could have a memory leak
    3. your app could just be creating too many/large objects and need redesign

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

  • Thread pool rejecting threads when I don't think it should, ideas?

    Hi,
    I have a server application in which I only want a specific number of simultaneous requests. If the server gets more then this number it is suppose to close the connection (sends an HTTP 503 error to the client). To do this I used a fix thread pool. When I start the server and submit the max number of requests I get the expected behavior. However if I resubmit the request (within a small period of time, e.g. 1-15 seconds after the first one) I get very odd behavior in that some of the requests are rejected. For example if I set the max to 100 the first set of requests will work fine (100 requests, 100 responses). I then submit again and a small number will be rejected (I've seen it range from 1 to 15 rejected)....
    I made a small app which kind of duplicates this behavior (see below). Basically when I see is that the first time submitting requests works fine but the second time I get a rejected one. As best as I can tell none should be rejected....
    Here is the code, I welcome your thoughts or if you see something I am doing wrong here...
    <pre>
    import java.util.concurrent.*;
    import java.util.concurrent.atomic.AtomicInteger;
    public class ThreadPoolTest {
         static AtomicInteger count = new AtomicInteger();
         public static class threaded implements Runnable {
              @Override
              public void run() {
                   System.out.println("In thread: " + Thread.currentThread().getId());
                   try {
                        Thread.sleep(500);
                   } catch (InterruptedException e) {
                        System.out.println("Thread: " + Thread.currentThread().getId()
                                  + " interuptted");
                   System.out.println("Exiting run: " + Thread.currentThread().getId());
         private static int maxThreads = 3;
         private ThreadPoolExecutor pool;
         public ThreadPoolTest() {
              super();
              pool = new java.util.concurrent.ThreadPoolExecutor(
                        1, maxThreads - 1, 60L, TimeUnit.SECONDS,
                        new ArrayBlockingQueue<Runnable>(1));
         public static void main(String[] args) throws InterruptedException {
              ThreadPoolTest object = new ThreadPoolTest();
              object.doThreads();
              Thread.sleep(3000);
              object.doThreads();
              object.pool.shutdown();
              try {
                   object.pool.awaitTermination(60, TimeUnit.SECONDS);
              } catch (InterruptedException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         private void doThreads() {
              int submitted = 0, rejected = 0;
              int counter = count.getAndIncrement();
              for (int x = 0; x < maxThreads ; x++) {
                   try {
                        System.out.println("Run #: " + counter + " submitting " + x);
                        pool.execute(new threaded());
                        submitted++;
                   catch (RejectedExecutionException re) {
                        System.err.println("\tRun #: " + counter + ", submission " + x
                                  + " was rejected");
                        System.err.println("\tQueue active: " + pool.getActiveCount());
                        System.err.println("\tQueue size: " + pool.getPoolSize());
                        rejected++;
              System.out.println("\n\n\tRun #: " + counter);
              System.out.println("\tSubmitted: " + (submitted + rejected));
              System.out.println("\tAccepted: " + submitted);
              System.out.println("\tRejected: " + rejected + "\n\n");
    </pre>

    First thank you for taking the time to reply, I do appreciate it.
    jtahlborn - The code provided here is a contrived example trying to emulate the bigger app as best as I could. The actual program doesn't have any sleeps, the sleep in the secondary thread is to simulate the program doing some work & replying to a request. The sleep in the primary thread is to simulate a small delay between 'requests' to the pool. I can make this 1 second and up to (at least) 5 seconds with the same results. Additionally I can take out the sleep in the secondary thread and still see the a rejection.
    EJP - Yes I am aware of the TCP/IP queue, however; I don't see that as relevant to my question. The idea is not to prevent the connection but to respond to the client saying we can't process the request (send an "HTTP 503" error). So basically if we have, say, 100 threads running then the 101st, connection will get a 503 error and the connection will be closed.
    Also my test platform - Windows 7 64bit running Java 1.6.0_24-b07 (32bit) on an Intel core i7.
    It occurred to me that I did not show the output of the test program. As the output shows below, the first set of requests are all processed properly. The second set of requests is not. The pool should have 2 threads and 1 slot in the queue, so by the time the second "request" is made at least 2 of the requests from the first call should be done processing, so I could possibly understand run 1, submit #2 failing but not submit 1.
    <pre>
    Run #: 0 submitting 0
    Run #: 0 submitting 1
    Run #: 0 submitting 2
    In thread: 8
    In thread: 9
    Exiting run: 8
    Exiting run: 9
         Run #: 0
         Submitted: 3
         Accepted: 3
         Rejected: 0
    In thread: 8
    Exiting run: 8
    Run #: 1 submitting 0
    In thread: 9
    Run #: 1 submitting 1
         Run #: 1, submission 1 was rejected
         Queue active: 1
         Queue size: 2
    Run #: 1 submitting 2
         Run #: 1
         Submitted: 3
         Accepted: 2
         Rejected: 1
    In thread: 8
    Exiting run: 9
    Exiting run: 8
    </pre>

  • JDBC pooling Oracle driver Socket read timed out

    I run Java EE application on Glassfish server v3 together with Oracle 12 DB on the same machine under Windows Server 2012 64bit. I use latest ojdbc7 driver.
    Connection pool config:
      <jdbc-connection-pool validation-table-name="DUAL" steady-pool-size="20" statement-cache-size="100" associate-with-thread="true" statement-timeout-in-seconds="30" idle-timeout-in-seconds="60" max-wait-time-in-millis="2000" validate-atmost-once-period-in-seconds="20" datasource-classname="oracle.jdbc.pool.OracleDataSource" pool-resize-quantity="5" max-pool-size="60" res-type="javax.sql.DataSource" name="dbPool" is-connection-validation-required="true">
      <property name="driverClass" value="oracle.jdbc.OracleDriver"></property>
      <property name="user" value="xxx"></property>
      <property name="url" value="jdbc:oracle:thin:@(DESCRIPTION=(ENABLE=BROKEN)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl)))"></property>
      <property name="password" value="xxx"></property>
      <property name="portNumber" value="1521"></property>
      <property name="databaseName" value="orcl"></property>
      <property name="serverName" value="127.0.0.1"></property>
      <property name="oracle.jdbc.ReadTimeout" value="300000"></property>
      <property name="oracle.net.CONNECT_TIMEOUT" value="10000"></property>
      </jdbc-connection-pool>
    After 2 or 3 hours, when there is more than 1 user (3-5) using my application, it stops responding and I get this in glassfish logs
      javax.enterprise.resource.resourceadapter.com.sun.enterprise.resource.allocator|_ThreadID=152;_ThreadName=Thread-2;|RAR5038:Unexpected exception while creating resource for pool dbPool. Exception : javax.resource.spi.ResourceAllocationException: Connection could not be allocated because: IO Error: Socket read timed out
      Local Exception Stack:
      Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
      Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: IO Error: Socket read timed out
    From the database side it looks like this
    Fatal NI connect error 12560, connecting to:
      (LOCAL=NO)
      VERSION INFORMATION:
      TNS for 64-bit Windows: Version 12.1.0.1.0 - Production
      Oracle Bequeath NT Protocol Adapter for 64-bit Windows: Version 12.1.0.1.0 - Production
      Windows NT TCP/IP NT Protocol Adapter for 64-bit Windows: Version 12.1.0.1.0 - Production
      Time: 13-JUN-2014 03:14:49
      Tracing not turned on.
      Tns error struct:
      ns main err code: 12560
      TNS-12560: TNS:protocol adapter error
      ns secondary err code: 0
      nt main err code: 0
      nt secondary err code: 0
      nt OS err code: 0
      opiodr aborting process unknown ospid (3404) as a result of ORA-609
    When I just reset db listener everything works ok for next 1-2 hours (depends on application load). So temporary solution is to run bat script from windows scheduler to reset the listener every 1h.
    I tried everything I could find - applied these parameters:
      - Sqlnet.ora:
      SQLNET.INBOUND_CONNECT_TIMEOUT=180
      SQLNET.EXPIRE_TIME=5
      - Listener.ora:
      INBOUND_CONNECT_TIMEOUT_LISTENER_IPC=120
    But still without success

    Is the problem here just that you need a connection pool that closes idle connections?  Some pools will close idle connections after a time out period.  And the pool lets you set that time out period.  If the pool you are using doesn't provide that then use a different pool.

Maybe you are looking for

  • Msi g4 ti 4200 td8x

    have just bought msi g4 ti 4200 td8x can anyone tell me if its ok to run the g4 ti 4200 on a 4xagp motherborord ---reason is i have 2 other mobos i would like to use the g4 ti 4200 on msi 845 ultra c and msi 845e max2 the manual says its 4x/8x but in

  • Alerts for Marketing Attributes in CRM 2007

    Hi We are using CRM 2007 and we have marketing attributes maintained on the Sold-to party business partner. We want this marketing attribute to be displayed in the interaction center when the agent confirms the account. How to configure Alerts (Inten

  • IPhoto Printing Templates

    Are there any "drag and drop" templates for photo size printing? I just loaded iPhoto '08 and it has some great new features. However, I still can not find the ability to drag a photo into a pre-designed template; i.e. 2-4x6 photos, 8-wallets, etc. I

  • Processing the return of consignment goods

    Hi , Can some one help me with teh steps involved in the processing of return of consignment goods , step by step

  • Imessage for mac os x 10.5.8 or 10.4.11

    Hello my name is Byron i am full Deaf i have Mac os X version 10.5.8 PowerPC G4  1 GB SDRAM i need want know do have anyone have old save that from imessage download in my desktop like  Ipad 3 64 have imessage iphone have also i want also in my compu