Thread Handling

Hello. I'm having a bit of a problem with the way I'm handling threads, quite obviously. At the moment, it appears that each thread I have running in my program uses a little over 10MG of memory. Is this normal? Assuming it is, is there any common and good method of handling threads that might reduce this?
My program currently requires a new thread to be created every time a new user logs in... which I believe is the only way it can be written because it requires input from each user on an unpredictable basis. That being said, even so much as 10 users would require 100MG plus my other executing threads... looking at 100 is thus rather rediculous... and I'm trying to create my program to allow for far more than 100. I know it can be done, so I'm rather confused as to why it is that I'm not doing it.
Thank you so much for your time,
-Jess

Thanks so much everyone for the replies. I started up a thread pool, as suggested, and that seems to be working well, so thanks for the idea... it doesn't, however, seem to account for the memory problems. this leads me to believe that perhaps there's something about Java I'm not understanding...
When I run my program, and then enter a ps from the command line, I get the following output: (which, is essentially 10 processes that each use up 0.6% of my host's memory... which is a total of 100MB. Thus accounting for 10 MB per process)
PID TTY      STAT   TIME  MAJFL   TRS   DRS   RSS %MEM COMMAND
26088 pts/2    S      0:00      1    56 260499 13636  0.6 java -classpath /home/src/classes engine.Server
26089 pts/2    S      0:00      0    56 260499 13636  0.6 java -classpath /home/src/classes engine.Server
26090 pts/2    S      0:00      0    56 260499 13636  0.6 java -classpath /home/src/classes engine.Server
26091 pts/2    S      0:00      0    56 260499 13636  0.6 java -classpath /home/src/classes engine.Server
26092 pts/2    S      0:00      0    56 260499 13636  0.6 java -classpath /home/src/classes engine.Server
26093 pts/2    S      0:00      0    56 260499 13636  0.6 java -classpath /home/src/classes engine.Server
26094 pts/2    S      0:00      0    56 260499 13636  0.6 java -classpath /home/src/classes engine.Server
26095 pts/2    S      0:00      0    56 260499 13636  0.6 java -classpath /home/src/classes engine.Server
26096 pts/2    S      0:00      0    56 260499 13636  0.6 java -classpath /home/src/classes engine.Server
26100 pts/2    S      0:00      0    56 260499 13636  0.6 java -classpath /home/src/classes engine.ServerPreviously, whenever a new user logged in, a new process would be created identical to the above, which is why I assumed that each process was a thread. So, in preliminary testing, I created a command which runs through the ThreadGroups of my main class (engine.Server), and then prints out the listing. The code is something like:
ThreadGroup group = server.getThreadGroup();
ThreadGroup parent = group.getParent();
while ( parent!=null )
     group = parent;
     parent = group.getParent();
group.list();This gives me a result of 6 threads:
java.lang.ThreadGroup[name=system,maxpri=10]
    Thread[Reference Handler,10,system]
    Thread[Finalizer,8,system]
    Thread[Signal Dispatcher,9,system]
    java.lang.ThreadGroup[name=main,maxpri=10]
        Thread[main,5,main]
        Thread[UpdateHandler,5,main]
        Thread[pool-1-thread-1,5,main]However I have ten processes running, which are consuming a pretty large amount of memory. I previously assumed that there were four other threads from a different thread group which were unaccounted for... but I'm not entirely sure that this is the case anymore.
Is there anything that strikes someone out there that could be accounting for 10 processes consuming 10MB each? I apologize for my ignorance, as I come from a C background where there was only ever one process when I ran (more or less) this same program... so I'm rather lost.
As well, I have a few statistics from my Runtime, but I think that is unneccesary. If it would help, I will post it, however.
Thanks so much for your help,
-Jess

Similar Messages

  • Creative Cloud Leaks Thread Handles

    I have Creative Cloud version 1.8.0.447 running on windows 7, and I notice that it leaks a Thread Handle, about 4 times, or so, per minute.  Since I leave my computer on most of the time, after a few days, the number of leaked Thread Handles is up in the tens of thousands.
    I can see the thread handles leaking using Process Explorer.
    Generally when a thread ends, its handle needs to be closed, or else the handle will stay active forever, or until the process ends.  It looks like the programming team is not closing these handles after the threads end.
    Please, adobe, fix this problem in a future release of creative cloud.
    -Todd

    Some 10.9.x links
    -next link says After Effects, but check YOUR permissions !!!
    -http://blogs.adobe.com/aftereffects/2014/06/permissions-mac-os-start-adobe-applications.ht ml
    -Mac 10.9.4 and OpenCL issue https://forums.adobe.com/thread/1514717
    -Mac 10.9.3 workaround https://forums.adobe.com/thread/1489922
    -more Mac 10.9.3 https://forums.adobe.com/thread/1491469
    -and https://forums.adobe.com/thread/1507936
    or
    A chat session where an agent may remotely look inside your computer may help
    Creative Cloud chat support (all Creative Cloud customer service issues)
    http://helpx.adobe.com/x-productkb/global/service-ccm.html

  • Secondary Indices and free-threaded handles

    As per the BerkeleyDB documentation, BDB manages synchronization if the db_handle is free-threaded (i.e opened with flag DB_CREATE).
    Example: Consider a free-threaded handle 'dbp' to the primary index and a free-threaded handle 'dbs' to the secondary index associated with 'dbp'. If one thread is trying to write using 'dbp' and another thread is trying to read using 'dbs', then does BDB maintain synchronization ?

    As per the BerkeleyDB documentation, BDB manages
    synchronization if the db_handle is free-threaded
    (i.e opened with flag DB_CREATE).
    Example: Consider a free-threaded handle 'dbp' to
    the primary index and a free-threaded handle 'dbs'
    to the secondary index associated with 'dbp'. If one
    thread is trying to write using 'dbp' and another
    thread is trying to read using 'dbs', then does BDB
    maintain synchronization ?Would you please clarify your question especially if my guess at what you are asking is incorrect?
    I can't tell if you are really talking about a handle or a cursor and you also mentioned a secondary index. .
    DB handles are free-threaded if the DB_THREAD flag is specified to the DB->open method when the database is opened or if the database environment in which the database is opened is free-threaded. The handle should not be closed while any other handle that refers to the database is in use; for example, database handles must not be closed while cursor handles into the database remain open, or transactions that include operations on the database have not yet been committed or aborted.
    You will also want to configure locking, see the DB_INIT_LOCK flag. Therefore you will likely want to configure a Berkeley DB Environment with the DB_INIT_LOCK | DB_THREAD flags added to your environment.
    If that was NOT what you were asking about please clarify your question or tell us what you are trying to accomplish?
    Ron Cohen
    Oracle Corporation

  • Swing Thread handling

    Dear all,
    The question is as the follow:
    Condition
    Class A purpose: Get Data from SQL server 2000 e.g.
    SQLDB transaction = new SQLDB();
    transaction.getData();
    Now, I would like to handle the transaction time in order to show that it is processing with Swing component: JLabel, JButton and JFrame. How to write a swing program? Please help me or give me some reference. Thank you so much for your help!
    Regards,
    kzyo

    If java 6, this is an article which I think will probably help you immensely:
    http://java.sun.com/developer/technicalArticles/javase/swingworker/
    It's all about how to implement SwingWorker, a background threader that can among other things give progress reports to the GUI.
    Message was edited by:
    petes1234

  • Thread handling on RMI

    Once exported the object to RMI service, it allows many client object to invoke the methods on RMI object.
    It can allow multiple invoke at the same time. Does it mean that RMI service handle multiple request by multi-thread?
    Can we control the number of request on RMI object? or It should be done by developer?

    You can do that because the previous answer was flat 100% 180 degrees wrong. RMI is and always has been multithreaded in all versions and implementations I have ever seen or heard of in over ten years.
    This bizarre rumour to the contrary surfaces occasionally. It frankly baffles me how anybody could believe it for a moment. Such a system would be almost completely useless.

  • Doubt in thread handling

    I have a doubt in the thread mechanism.....
    Below is a sample of the class
    public class SimpleThread extends Thread {
    private int countDown = 5;
    private static int threadCount = 0;
    public SimpleThread() {
    super("" + ++threadCount); // Store the thread name
    start();
    public String toString() {
    return "#" + getName() + ": " + countDown;
    public void run() {
    while(true) {
    System.out.println(this);
    if(--countDown == 0) return;
    public static void main(String[] args) {
    for(int i = 0; i < 5; i++)
    new SimpleThread();
    There is a while loop checks for true.... I am not able to understand which it is referring to .
    and i want to run the thread 5 times .... is it possible to run this using while loop... Because when i use while the loop never end...
    Your guidance is much more appreciated...
    Thankyou
    Shasi

    Hi,
    sorry, but your question seems to be a little confusing.
    shasi wrote:
    I have a doubt in the thread mechanism.....Do you actually have a doubt or more something of a question? To me, it seems to be more of a question...
    Below is a sample of the classPlease use the code tags to format your code for better readability...
    public class SimpleThread extends Thread {
         private int countDown = 5;
         private static int threadCount = 0;
         public SimpleThread() {
              super("" + ++threadCount); // Store the thread name
              start();
         public String toString() {
              return "#" + getName() + ": " + countDown;
         public void run() {
              while(true) {
                   System.out.println(this);
                   if(--countDown == 0) return;
         public static void main(String[] args) {
              for(int i = 0; i < 5; i++)
                   new SimpleThread();
    There is a while loop checks for true.... I am not able to understand which it is referring to .What should it be referring to? The while loop has to be given some statement that evaluates to a boolean. This could either be something like a > 10 or simply true.
    and i want to run the thread 5 times .... is it possible to run this using while loop... Because when i use while the loop never end...You do run the Thread five times. Or are you talking about executing the loop in your run() method for five times (which you also happen to do already)?
    What do you want to run using a while loop?
    The while loop will end: with each iteration, your countdown variable is being decremented, and as soon as it reaches zero, the return statement is executed breaking out of the while loop.
    Bye.

  • How do you dispose a thread-handled modal dialog not thru some actions?

    The code almost looks like this:
    /* Thread that disposes the dialog when the time in seconds is "9" */
    class AboutThread extends Thread {
    private volatile Thread about;
    AboutDialog ad;
    AboutThread(AboutDialog ad) {
    this.ad = ad;
    public void stopped() {
    about = null;
    ad.dispose();
    ad = null;
    System.gc();
    public synchronized void run() {
    Thread thisThread = Thread.currentThread();
    about = thisThread;
    System.out.println("About thread is running!");
    ad.start();
    while (about == thisThread) {
    try {
    Thread.sleep(1000);
    } catch (InterruptedException ex) {
         System.err.println("Thread.sleep error: " + ex);
    String s = new String(getCurrentDateTime("s"));
    if (s.equals("9")) {
    ad.setVisible(false);
    ad.setModal(false);
    ad.setVisible(true);
    System.out.println(9);
    this.stop();
    /* Shows a dialog describing the User Log application */
    public class AboutDialog extends Dialog implements ActionListener {
    public AboutDialog(Frame parent, String title) {
         super(parent, title, false);
         Panel labelPanel = new Panel();
         labelPanel.setLayout(new BorderLayout());
         labelPanel.setBackground(Color.gray);
    JLabel jlab = new JLabel("User Log 1.0");
    jlab.setHorizontalAlignment(SwingConstants.CENTER);
    jlab.setFont(new Font("Monospaced", Font.BOLD, 28));
    JLabel jlab1 = new JLabel("Copyright(c) 2001 Soft Wares. All Rights Reserved.");
    jlab1.setHorizontalAlignment(SwingConstants.CENTER);
    labelPanel.add(jlab, "Center");
         labelPanel.add(jlab1, "South");
         add(labelPanel, "Center");
         Panel buttonPanel = new Panel();
    buttonPanel.setBackground(Color.gray);
         Button okButton = new Button("OK");
         okButton.addActionListener(this);
         buttonPanel.add(okButton);
         add(buttonPanel, "South");
         setSize(400, 130);
         setLocation(parent.getLocationOnScreen().x + 200,
              parent.getLocationOnScreen().y + 200);
    public void start() {
    show();
    public void actionPerformed(ActionEvent e) {
         setVisible(false);
         dispose();
    at.stopped();
    }

    ooops! i'm sorry. in the AboutDialog Class, it should be "super(parent, title, true)" for it to be modal.
    anyway, it seemed that posting the partial code above of the whole app is not so understandable.
    what i like to address here is that: how do i dispose or get rid of the thread-dispatched modal dialog by not making mouse clicks or any other user intervention? i wanted it to be disposed by the same thread, which dispatched it, when a certain variable value (global or local) is met. is this possible?

  • Java Thread Handling

    Hi,
    I've been poking around in the site but haven't been able to find the answer: does Java dispatch threads to different cores when it has control of the processor(s) or does the JVM internally decide which thread gets control of the processor(s)?
    Thanks.

    Thanks...I seemed to remember that Java decided but I wasn't sure and was in fact correct.
    Speaking of which - can you perhaps link me or tell me what terms to search under so I can get some Sun documentation on this and read up about it? I am most interested in the details.
    Thanks !

  • How to handle threading for TCP communicat​ion?

    Hi,
    I've a project to control two separate applications (C++ and LabView) and both of them are implemented as server. Another client program (C++) is used to control those application. The communication among them are implemented using TCP socket. The client program sends message to start or stop some tasks on the servers. The client program also sends time (hh:mm:ss) with the start and stop message to determine when to start or stop.
    In C++ application (server): The application listens for connection and when gets  one, it creates a communication thread to handle that and again listen for another connection. The communication thread handles message passing and when it receives start or stop message, it creates a timer thread with the received time to trigger a task at specified time. And after that it waits for message from the client. So, here, when thread (communication, timer) is needed, it is created.
    In LabView (server): I've tried to create same thing as the C++ server. But, from LabView manual and others forum threads, I got that LabView is multithreading and it can be done using independent loop. So, I'd to create four loops in a diagram:
    1. Listen for new connection
    2. Handle communication for already received connection
    3. Start timer
    4. Stop timer
    and they are run at the beginning of the execution and communication among them are managed using local variables. But, 2,3 and 4th loop can handle only one connection and it can handle another if the current is closed. But, the C++ application can handle more than one connection by creating thread when it is necessary but not at the beginning of the execution of the application.
    Is there a better way to implement this in LabView?
    Is it possible to handle multiple connections and create diagram node/block (like thread) dynamically like C++?
    Thanks.
    Using LabVIEW 2010, Visual C#, Visual C++ (2005, 2008, 2010)
    Solved!
    Go to Solution.

    There are several ways to do this in modern LabVIEW and you should probably search the Example Finder for some TCP examples. The classic way is to transfer the connection refnum from the listen loop to a communication loop that adds it to an array of connection IDs and then continously iterates over this array to do the communication. It works since about LabVIEW 4.0 perfectly for me even for applications with HTTP based communication protocol. But you need to make sure of course that the communciation handling for one connection isn't delaying its work for some reasons as that would delay the handling of the other connections too, as they are really worked on sequentially. If you encounter an error, the connection ID is closed and removed from the array.
    The other is that you create a VI that does your whole communication and terminates itself on an error or when getting the quit command. Make this VI to be reentrant and then launch it through VI server as reentrant instance, passing it the newly received connection refnum form the listen loop. Then use the Run method to let it start and operate like an independant thread.
    For all of these you should be able to find an example in the Example Finder when searching for TCP.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • A problem about event-driven and multi-thread ( maybe?)

    I am thinking of doing a piece of small software. I am going to write a server, storing some dynamic information. and each client (surely in different threads) has a JList, which is supposed to update itself with server, such as adding an item, etc.
    a straightforward example is an IM software, each client stores a list of online buddies, and if a new client logs in, many other clients have to update the buddies list.
    What is a good approach of doing that? I am thinking of adding a public method, addItem() into the thread handler, which adds a new item into the JList. but is it a good design to have a public method other than "run()" in the thread handler?
    Or do I have to define a new event of new item needed to be added?
    Thanks.

    Actually I am just asking for how to design a good communication between the server and the client...
    so just as a client A logging in, the server knows that the client A has logged in, and A,B are friends, B's friend lists should be updated, which means adding A to that list. so I am thinking have a addItem() method in the thread handler of B, so I can call ThreadHandlerB.addItem( A ) in the code of the server, since server knows that A has logged in.
    or is there any good approach? And most importantly, is it a safe way to have a public method in the thread handler?
    Thanks so much!

  • JDK 1.6 on Solaris. Multiple java processes and thread freezes

    Hi, we've come across a really weird behavior on the Solaris JVM, reported by a customer of ours.
    Our server application consists of multiple threads. Normally we see them all running within a single Java process, and all is fine.
    At some point in time, and only on Solaris 10, it seems that the main Java process starts a second Java process. This is not our code trying to execute some other application/command. It's the JVM itself forking a new copy of itself. I assumed this was because of some JVM behaviour on Solaris that uses multiple processes if the number of threads is > 128. However at the time of spawn there are less than 90 threads running.
    In any case, once this second process starts, some of the threads of the application (incidentally, they're the first threads created by the application at startup, in the first threadgroup) stop working. Our application dumps a list of all threads in the system every ten minutes, and even when they're not working, the threads are still there. Our logs also show that when the second process starts, these threads were not in the running state. They had just completed their operations and were sleeping in their thread pool, in a wait() call. Once the second process starts, jobs for these threads just queue up, and the wait() does not return, even after another thread has done a notify() to inform them of the new jobs.
    Even more interesting, when the customer manually kills -9 the second process, without doing anything in our application, all threads that were 'frozen' start working again, immediately. This (and the fact that this never happens on other OSes) makes us think that this is some sort of problem (or misconfiguration) specific to the Solaris JVM, and not our application.
    The customer initially reported this with JDK 1.5.0_12 , we told them to upgrade to the latest JDK 1.6 update 6, but the problem remains. There are no special JVM switches (apart from -Xms32m -Xmx256m) used. We're really at a dead end here in diagnosing this problem, as it clearly seems to be outside our app. Any suggestion?

    Actually, we've discovered that that's not really what was going on. I still believe there's a bug in the JVM, but the fork was happening because our Java code tries to exec a command line tool once a minute. After hours of this, we get a rogue child process with this stack (which is where we are forking this command line tool once a minute):
    JVM version is 1.5.0_08-b03
    Thread t@38: (state = IN_NATIVE)
    - java.lang.UNIXProcess.forkAndExec(byte[], byte[], int, byte[], int, byte[], boolean, java.io.FileDescriptor, java.io.FileDescriptor, java.io.FileDescriptor) @bci=168980456 (Interpreted frame)
    - java.lang.UNIXProcess.forkAndExec(byte[], byte[], int, byte[], int, byte[], boolean, java.io.FileDescriptor, java.io.FileDescriptor, java.io.FileDescriptor) @bci=0 (Interpreted frame)
    - java.lang.UNIXProcess.<init>(byte[], byte[], int, byte[], int, byte[], boolean) @bci=62, line=53 (Interpreted frame)
    - java.lang.ProcessImpl.start(java.lang.String[], java.util.Map, java.lang.String, boolean) @bci=182, line=65 (Interpreted frame)
    - java.lang.ProcessBuilder.start() @bci=112, line=451 (Interpreted frame)
    - java.lang.Runtime.exec(java.lang.String[], java.lang.String[], java.io.File) @bci=16, line=591 (Interpreted frame)
    - java.lang.Runtime.exec(java.lang.String, java.lang.String[], java.io.File) @bci=69, line=429 (Interpreted frame)
    - java.lang.Runtime.exec(java.lang.String) @bci=4, line=326 (Interpreted frame)
    - java.lang.Thread.run() @bci=11, line=595 (Interpreted frame)There are also several dozen other threads all with the same stack:
    Thread t@32: (state = BLOCKED)
    Error occurred during stack walking:
    sun.jvm.hotspot.debugger.DebuggerException: can't map thread id to thread handle!
         at sun.jvm.hotspot.debugger.proc.ProcDebuggerLocal.getThreadIntegerRegisterSet0(Native Method)
         at sun.jvm.hotspot.debugger.proc.ProcDebuggerLocal.getThreadIntegerRegisterSet(ProcDebuggerLocal.java:364)
         at sun.jvm.hotspot.debugger.proc.sparc.ProcSPARCThread.getContext(ProcSPARCThread.java:35)
         at sun.jvm.hotspot.runtime.solaris_sparc.SolarisSPARCJavaThreadPDAccess.getCurrentFrameGuess(SolarisSPARCJavaThreadPDAccess.java:108)
         at sun.jvm.hotspot.runtime.JavaThread.getCurrentFrameGuess(JavaThread.java:252)
         at sun.jvm.hotspot.runtime.JavaThread.getLastJavaVFrameDbg(JavaThread.java:211)
         at sun.jvm.hotspot.tools.StackTrace.run(StackTrace.java:50)
         at sun.jvm.hotspot.tools.JStack.run(JStack.java:41)
         at sun.jvm.hotspot.tools.Tool.start(Tool.java:204)
         at sun.jvm.hotspot.tools.JStack.main(JStack.java:58)I'm pretty sure this is because the fork part of the UnixProcess.forkAndExec is using the Solaris fork1 system call, and thus all the Java context thinks all those threads exist, whereas the actual threads don't exist in that process.
    It seems to me that something is broken in UnixProcess.forkAndExec in native code; it did the fork, but not the exec, and this exec thread just sits there forever. And of course, it's still holding all the file descriptors of the original process, which means that if we decide to restart our process, we can't reopen our sockets for listening or whatever else we want to do.
    There is another possibility, which I can't completely rule out: this child process just happened to be the one that was fork'd when the parent process called Runtime.halt(), which is how the Java process exits. We decided to exit halfway through a Runtime.exec(), and got this child process stuck. But I don't think that's what happens... from what I understand that we collected, we see this same child process created at some point in time, and it doesn't go away.
    Yes, I realize that my JVM is very old, but I cannot find any bug fixes in the release notes that claim to fix something like this. And since this only happens once every day or two, I'm reluctant to just throw a new JVM at this--although I'm sure I will shortly.
    Has anyone else seen anything like this?

  • Problem about Sparc/solaris10 signal in multi-thread environment

    Normally if we send a signal to a process which has several threads, the main thread of this process will handle this signal. But I found in some cases an other thread (not main thread) handled signals even if main thread was alive(mostly main thread was being blocked by __pollsys()).
    I want to know why and how this happens.
    Thanks.

    according to man signal.h from a solaris 10 machine ...
    Asynchronously generated signals are not directed to
    a particular thread but are handled by an arbitrary thread
    that meets either of the following conditions:
    .... a list of conditions.
    So if you have threads that you don't want to take signals, then those threads
    must block that signal eg pthread_sigmask()
    it is just chance that it usually goes to your "main" thread.
    tim

  • Reg : EventDispatcher Thread

    Dear All,
    I have some doubts in EventDispatcher thread. As everyone know, java provides the option for creating a modal dialog. But the problem here is, it is modal to entire jvm. My requirement is i have to create modal dialog based on some context ( only for two three frames & dialogs). So I have written a class which extends the EventQueue and put it in top of EventQueue stack.
    The above methodology allow me to dispatch the events based on my condition. I have created all the dialogs as non modal one and event restriction can be applied from extended eventqueue.
    The problem here is, I can not pause the thread (until the dialog closed).Since it is EventDispatchThread, i can not use while(true) methodlogy.
    Please help me in this regard
    Thanks and Regards
    V.S.Saravanan

    Swing and Thread handling...
    http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html

  • Waiting for a thread to die.

    Hello, I hope you can help me...
    I am writting a jdk1.4.1 Swing application that displays a small animation. This animation is processed from within a separate thread. My program makes a call starting this 'animation thread'. For practical reasons my program needs to wait for this thread to die (and thus the full animation to be shown) before it can continue. I am waiting for the animation thread to die using Threads 'join' method. However the problem with this is that I am forcing the GUI thread to wait resulting in the animation being calculated but not displayed. And so... how can I fix this... all I want is to wait until the animation is shown.
    What I would like to do is:
    1. Start animation;
    2. wait intil animation has completed;
    3. continue with program.
    Any help or advice will be greatly appreciated.
    Thank you in advance.

    Maybe this design could work for you. You divide your program into three parts running in three separate threads.
    1. The main thread handling GUI stuff and coordination of the two other threads.
    2. A working thread doing most of what the main thread is now doing.
    3. The animation thread.
    With this division of labour the working thread is waiting for the animation thread to finish (the main GUI thread isn't). The main thread will be free at all times to react to the users input or updating the screen or whatever, while the other two threads are cooperating to produce the animation.

  • ThreadPoolExecutor- Thread termination

    I created a thread pool executor and submitted some callable tasks to thread pool and waiting on future object in the method futureobject.get(timeout, TimeUnit.SECONDS).
    Once it is timed out i am catching the TimeoutException and cancelling the task through future.cancel(ture),
    But it is just interrupting the thread and not cancelling the task if the task has already started executing.
    Is there any way to stop the future Object task after a certain time out irrespective of its current state?
    I want to terminate the thread execution and make the thread pick another task once if it is timed out.
    One way is to interrupt the thread which is handling the future object task and then stop the thread.
    Is there any other way that I can cancel a future Object task directly without dealing with the thread handling this future object task.
    Can you throw a light on this. Any idea would be helpful...!!
    Thanks in advance.

    Thanks Peter for your reply.
    But the problem is the thread is not like executing in a while loop to test every time whether it is interrupted or not by future.cancel(ture).
    As my callable task is calling internally more methods which are call some more methods of other classes in this i cant put every where this logic to check whether thread is interrupted or not.
    Even i have done that my concern is what if thread is executing a method long time because of some blocking problem. i need to wait the control comes back after method to check whether thread is interrupted or not. which is not desired..
    let me put in an example.
    public Object call(){
    new ArrayList list=SampleClass1Object.readData();
    // check whether thread is interrupt by future.cancel() method
    Object ob= SampleClass2Object.display(list);
    return ob;
    If i fix time in future.get(timeout,TimeUnit). when the time out is happend the thread executing the method readData() it wont reflect immediately once this readData() method is completed then only it will check whether the thread is interrupted or not. This what is happening right now in my case.

Maybe you are looking for