Killing thread after timeout (j2se 5)

Hi. thread.stop and thread.destroy() is deprecated. The javadoc for thread.stop() recommends the thread to check a flag to see if it should commit suicide. My problem is that the thread uses an method which locks making the thread unable to check if it should die (code below). How can I externally kill that thread?
Thread t = new Thread(){
public void run(){
Spring s = new Spring();
Tools.p(Tools.DEBUG, "Returverdi fra spring-algoritme: %s", s.compute(g, gu));
t.start();
t.join(10000);
if (t.isAlive) t.stop() //but stop is deprecated... alternatives?
Sincerely
Fredrik 

Let me restate the question to be sure I understand:
You want to launch a possibly long duration process and let it run for a specified time. If it's still running, you want to kill it. If that's the case, something like this:
public void run() {
   try {  doLongProcess(); }
   catch ( InterruptedException e ) {  }
}Externally, interrupt the thread when time is up.

Similar Messages

  • Killing thread after JOptionPane

    I have a class that is not a GUI object but it calls a JOptionPane to display a message popup... I do not provide a parent to this JOptionPane. Im writing a unit test for this class and notice that after my last statement there are still living threads. I am guessing the gui thread. Is there a way to kill the GUI thread associated with the JOptionPane after it is displayed. Or do I have to do a system.exit at the end of the application that will end up using this class ????

    Let me restate the question to be sure I understand:
    You want to launch a possibly long duration process and let it run for a specified time. If it's still running, you want to kill it. If that's the case, something like this:
    public void run() {
       try {  doLongProcess(); }
       catch ( InterruptedException e ) {  }
    }Externally, interrupt the thread when time is up.

  • How to kill thread

    I am facing the problem in killing the thread after some interval. If anybody knows how to kill the thread in middle plz give me reply
    Thanks
    Sreedhar

    Thread.interrupt()
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thre
    ad.html#interrupt() is not about killing or stopping
    a thread. It is more about kicking a blocked thread.
    There is no way to kill a thread. As been said
    above, the thread should be designed to accept
    instruction to stop gracefully.
    The interrupt() was created by sun as a solution sun came up for the problems of thread stop(), it should be the cannonical way to stop a thread.
    The problem with having your own mechanism of interrupting a thread is that you should have a method to interrupt a thread execution and a flag that should be checked from inside your thread or runnable code to see if it should stop and if so, do it cleanly. The problem with this aproach is that if the thread is sleeping or in some blocked state, calling your own interruption framework is inefective, as it could never get a chance to run the code.
    To solve that, sun privides us with the method( interrupt() ) and the flag ( Thread.interrupted() ) with the advantage that on calling it, it guarantees you that it would take effect even if the thread is in a blocked state.
    So, you are right about having to implement your own gracious interruption but the right way to do that is by checking interrupted(). And no Thread.interrupt() is not just about blocked threads, although it covers that ground.
    May the code be with you.

  • Stop threads after a certain time

    I want to create a program that wants to do some work simultaneously, but each thread will return back after some time, however I do not want to wait forever so I want to stop all active threads after say 1 minute. Below is what I am doing but I am unable to stop the executing threads:
    ThreadPoolExecutor tpe = new ThreadPoolExecutor(
    tpSize, tpSize, 5, TimeUnit.MILLISECONDS,
    new LinkedBlockingQueue<Runnable>());
    Task[] tasks = new Task[nTasks];
    for (int i = 0; i < nTasks; i++) {
    tasks[i] = new Task(n, "Task " + i);
    tpe.execute(tasks[i]);
    tpe.shutdown();
    System.out.println("Done!");
    try {
    tpe.awaitTermination(5, TimeUnit.MILLISECONDS);
    catch (Exception e) {e.printStackTrace();}
    class Task implements Runnable {
    long n;
    String id;
    private long fib(long n) {
    if (n == 0)
    return 0L;
    if (n == 1)
    return 1L;
    return fib(n - 1) + fib(n - 2);
    public Task(long n, String id) {
    this.n = n;
    this.id = id;
    public void run() {
    Date d = new Date();
    DateFormat df = new SimpleDateFormat("HH:mm:ss:SSS");
    long startTime = System.currentTimeMillis();
    d.setTime(startTime);
    System.out.println("Starting task " + id + " at " + df.format(d));
    System.out.print("Fib: " + fib(n));
    long endTime = System.currentTimeMillis();
    d.setTime(endTime);
    System.out.println(" Ending task " + id + " at " + df.format(d) + " after " + (endTime - startTime) + " milliseconds");
    How come the threads do not stop especially when I have set a 5 Millisecond timeout?
    How do I go about stopping active threads?
    Message was edited by:
    dawuad

    I want to create a program that wants to do some work simultaneously, but each thread will return back after some time, however I do not want to wait forever so I want to stop all active threads after say 1 minute. Below is what I am doing but I am unable to stop the executing threads:
    ThreadPoolExecutor tpe = new ThreadPoolExecutor(
    tpSize, tpSize, 5, TimeUnit.MILLISECONDS,
    new LinkedBlockingQueue<Runnable>());
    Task[] tasks = new Task[nTasks];
    for (int i = 0; i < nTasks; i++) {
    tasks = new Task(n, "Task " + i);
    tpe.execute(tasks);
    tpe.shutdown();
    System.out.println("Done!");
    try {
    tpe.awaitTermination(5, TimeUnit.MILLISECONDS);
    catch (Exception e) {e.printStackTrace();}
    class Task implements Runnable {
    long n;
    String id;
    private long fib(long n) {
    if (n == 0)
    return 0L;
    if (n == 1)
    return 1L;
    return fib(n - 1) + fib(n - 2);
    public Task(long n, String id) {
    this.n = n;
    this.id = id;
    public void run() {
    Date d = new Date();
    DateFormat df = new SimpleDateFormat("HH:mm:ss:SSS");
    long startTime = System.currentTimeMillis();
    d.setTime(startTime);
    System.out.println("Starting task " + id + " at " + df.format(d));
    System.out.print("Fib: " + fib(n));
    long endTime = System.currentTimeMillis();
    d.setTime(endTime);
    System.out.println(" Ending task " + id + " at " + df.format(d) + " after " + (endTime - startTime) + " milliseconds");
    How come the threads do not stop especially when I have set a 5 Millisecond timeout?
    How do I go about stopping active threads?
    Is ThreadPoolExecutor right for me?

  • Stopping thread with timeout using threadpool

    Is there any way to set thread timeout within Executor.newFixedThreadPool ? I have a long queue around 5M which is creating with:
    ExecutorService executor = Executors.newFixedThreadPool(500);
    total = 10000;
    while (totalRows > 0) {
                    localStatement.executeQuery("SELECT domainID, domain FROM com WHERE status = '' LIMIT " + total);
                    totalRows -= total;
                    localResultSet = localStatement.getResultSet();
                    while (localResultSet.next()) {
                        HttpGet httpget = new HttpGet("http://" + localResultSet.getString("domain").toLowerCase());
                        executor.submit(new GetThread(httpClient, httpget, localResultSet.getInt("domainID")));
                    Thread.sleep(1000);
                    while (((ThreadPoolExecutor) executor).getActiveCount() > 10) {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                    localResultSet.close();
                    System.out.println("New cycle");
                }But sometimes threads lock and cycle can't finish. Is there anyway to stop thread after N seconds? I can encapsulate Runnable into another Runnable and stop it from there, but it doubles threads, and I believe its not a good way.

    yes, you need at least one more thread. you could use one thread to monitor multiple other threads, but you need at least one more thread to wake up after the timeout and check on/cancel the main task.

  • How to kill threads in obiee server

    Can some one please tell me how to kill threads in OBIEE server

    944632 wrote:
    Thanks for the prompt reply. your answer is helpful. Here is my problem.
    I am an OBIEE admin and getting lot of complaints fronm developers that BI Server services are not stopping. I was adviced by my senior that i have to kill thresads in the server.
    I followed what you told but when i open the RPD, i am unble to open cache in either offline or online modeHi,
    - Unable to open cache due to you already disabled cache (usage tracking - nqsconfig.ini file) cache diabled that why you can't able to open cache
    just make sure
    [CACHE]
    ENABLE = YES;
    C:\Oracle\Middleware\instances\instance1\config\OracleBIServerComponent\coreapplication_obis1 (obiee11g file path ref)
    - unable to stop biservices? if that case you can kill it different ways, (stop bi services/ctrl +c on services/task manager/FMW (console/EM)/ services.msc etc) which way did you tried?
    (which version did u tired)
    Thanks
    Deva

  • HTTP/RFC Session was deleted after timeout

    Hi all,
    several of my colleagues are working in CRM Web UI.
    Sometimes they just got logged of from the system.
    The only hint I can see in sm21 is "HTTP/RFC Session was deleted after timeout" (translated from german) with no additional info.
    Has someone faced similar issues?
    regards
    Davor

    Hi Rishi,
    thank you for the answer. Sorry, I forgot to mention, that I already checked ICM parameters. The timeout is set to 2700 seconds and proc-timeout is set to -1.
    Here is some confusing info I found in sm21 (also translated from german):
    Usualy there is no timeout for RFC-Server... An explicit timeout for a RFC-Session can be set with the function module TH_SET_AUTO_LOGOUT. If for a defined time no funcion-calls arrive, the RFC-Server will be deleted. If the client calls the server after deletion, the client will be rejected with an error-code.
    Hope, this helps. I have no clue!

  • Java Thread.sleep(timeout) is influenced by changes to System time on Linux

    Java Thread.sleep(timeout) is influenced by changes to System time on Linux
    bugId : 6311057
    I encountered this problem in redhat6/ jdk 1.6

    890651 wrote:
    Java Thread.sleep(timeout) is influenced by changes to System time on Linux
    bugId : 6311057
    I encountered this problem in redhat6/ jdk 1.6At least half the time I use it, I'd want it to be, the other half I wouldn't care.
    What are you doing with it where this might be a problem?
    Changing the system clock abruptly can cause all kinds of problems with your system anyway, because various background activities etc. often depend on file dates. Wherever possible use the "skew" method to adjust your system clock, rather than just plonking in a new value, especially if you are setting the clock backwards.

  • JPDA Examples TTY kill thread.

    Hi all:
    I've try to run the example com.sun.tools.example.debug.tty.TTY it works pretty well but I dont understand exactly how to use the command kill:
    kill <thread> <expr> -- kill a thread with the given exception object
    <expr>: a Java(tm) Programming Language expression.
    I dont understand exactly what they mean with the <expr> I've try kill 5 new java.lang.String("Killed") or kill 5 new java.lang.Throwable("Killed")
    Did someone here knows how to use JPDA to kill a thread?
    Can you give me an syntax example for that command?
    Thanks for any help.

    I've found a similar post at
    http://forum.java.sun.com/thread.jsp?forum=47&thread=274201
    timbell tells to use the following syntax:
    kill 0x129 new java.lang.Exception()
    but in my case I've try
    Reference Handler[1] suspend 29
    Reference Handler[1] kill 29 new java.lang.Exception()
    killing thread: 142.120.93.217_170_Receive
    Reference Handler[1] Thread not suspended
    Expression must evaluate to an object
    And it does'nt seems to work.
    Any helps will be appreciate.
    Thanks

  • How to start a thread after the execution/termination of another thread.???

    Hello,
    How to start a thread after the execution/termination of another thread....???
    For example:
    consider two threads: ThreadA and ThreadB
    I could start the ThreadB after the execution of ThreadA.
    How to identify the termination of one thread.....???
    Please help me...
    Thanks & Regards,
    Kayalvizhi

    What do you mean with "it doesn't work"? Do you get a compiler error? Do you get an exception at runtime? What's the error message?
    Jesper

  • How to stop version check that happens in the background after timeout?

    Hi all,
    I have a problem that seriously makes my swing application (installed using webstart) very slow for some time.
    Steps to reproduce my problem :
    1. Deploy the jars of application in the web server running on Machine A( either in LAN or running on public IP).
    2. Download the application on Machine B using the link.
    3. Shutdown Machine A.
    4. Now try to start the application on Machine B. The starting of the application has become very slow.
    After some time(long enough) the application is started. Even now, the application is slow for first few minutes.
    Below is the part of jnlp that we used.:
    +<?xml version="1.0" encoding="utf-8"?>+
    +<jnlp spec="1.0" codebase="$$codebase" href="LaunchMyApplication.jnlp">+
    +<information>+
    +<title>My Application</title>+
    +<vendor>XYZ</vendor>+
    +<description kind="short">XXXXXXXX</description>+
    +<icon href="../../../../images/myapp_splash2009.gif" kind="splash"/>+
    +<icon href="../../../../images/myapp_logo.jpg"/>+
    +<offline-allowed/>+
    +</information>+
    +<security>+
    +<all-permissions/>+
    +</security>+
    +<resources>+
    +<property name="abc.type" value="client"/>+
    +<j2se version="1.5" initial-heap-size="48m" max-heap-size="256m"/>+
    +     +
    +     <!-- jar details -->+
    +     ...........+
    +     ..........+
    +     +
    +</resources>     +
    +<application-desc main-class="com.abc.xyz.Login">+
    +     <argument>..........</argument>+
    +</application-desc>+
    +</jnlp>+
    My assumsion is
    When I start my application, version checking will happen. But the cache server system(machine A) is not available. Due to this initial slowdown has occurred.
    After the timeout has occured, my application has started. Since the version checking continuous in the background, my application is again slow.(Even when my application server and database system are in the same LAN of my client machine).
    This slowdown is certainly not desirable.
    This slowness isn't there when there Machine A( in which my webserver is installed) is running and my webserver (Tomcat 5.0 in my case) is not started.
    Is my assumsion is correct?
    If correct, how do I stop version checking process that happens in the background after initial timeout?
    I think update check and policy attribute may not help me as I wanted to stop this background version check altogether. Also, my java sersion is 1.5_0_14.
    Please help me out in this.
    Thanks in advance..,
    Chakri.

    Talk to Apple here...
    http://www.apple.com/feedback/

  • Killing Threads

    Hello all,
    I'm using oracle chart builder for presenting data in my
    application. I use it after supplying its data for gif file
    generation. The chart is stacked bar but I don't think this is the
    problem.
    The problem is that it generates the gif file successfully but my
    application is still running after the main method is finished, I
    debugged it and I found about three threads are up:
    Thread[AWT-EventQueue-0]
    Thread[SunToolkit.PostEventQueue-0]
    Thread[AWT-Windows]
    I doubted my code - but I'm taking it copy paste from developer's
    guide - and I debugged another Java file from a sample that comes with
    the kit and the same problem happened ?!?!?
    Does anyone know y?
    I saw lots of SunToolkit.PostEventQueue-0 problems here in google
    groups, but I don't find matching my situation.
    I used in testing both Oracle JDeveloper 9i release 3, and IBM
    WebSphere Studio Application Developer 4.0.3
    Thankx

    That will not work because these are threads started by the event handlers and gui objects not by processes he wrote. I honestly do not know that it is possible to kill these threads. I know you could have used something like the stop process in the past but not any longer. System.exit is really the only way I have seen to do things like that. I would say that maybe the best sollution you could hop for is to keep the window active even when the user closes it so then when they later ask for it again you can return the same window and keep it to those three threads being the only extra ones you have running.

  • Automatically Kill session after 30 min.....

    Hi All,
    I have set the heatbeat parameter in formsweb.cfg to 60 mins. but still the session is getting killed after 15 min...... can anybody help me to make the idle timeout setting to 30 mins...... thanks.... i m using application server version 10.2.1
    thanks...

    A good place to ask questions and advice about web development is at the mozillaZine Web Development/Standards Evangelism forum.<br />
    The helpers at that forum are more knowledgeable about web development issues.<br />
    You need to register at the mozillaZine forum site in order to post at that forum.<br />
    See http://forums.mozillazine.org/viewforum.php?f=25

  • Why is iMessage splitting group conversations into multiple threads after upgrading to iOS 8?

    After upgrading to iOS 8 my group messages keep getting split up into different threads. Everybody in the threads have iPhones and before upgrading they were all working and sending/receiving iMessages just fine.
    Now I'll have 2-3 threads with the same contacts (using their same phone numbers, not another contact point like iCloud email, Apple ID, etc.). My phone sometimes recognizes that the group is the same because it will automatically name the group the same thing, but other times it just puts the names of the people in the "To" line. In addition, some of the threads won't let me send iMessage so I have to reply in one thread and receive messages in the other (I send iMessages in thread A but the replies from the same people come back in thread B, but if I try and reply in thread B I can only send text messages even though all contact info is the same).
    Update after OS X Yosemite: After upgrading to Yosemite, my Messages app on my MacBook Pro is now splitting the threads as well. It used to be that the computer understood the contacts were the same so all messages should be under one thread and just my phone was having this issue, but the upgrade changed that.
    I have tried signing in and out of iMessage, upgrading to the latest iOS, turning on and off my phone, starting new groups, only replying to certain groups, etc. but nothing has worked.
    Thanks!

    Im having the same problem. This started with iOS 8 and Yosemite. Im in a group message with 10 people with and without iPhones. Currently have 9 threads and when ever a new person responds a new thread forms. they all have the same people but in a different order, that may be part of the reason why iMessage doesn't recognize them as the same conversation.
    As I'm writing this post 3 new threads opened and other people with and without iPhones are mentioning the same problem
    hope apple can fix this. VERY annoying

  • How can I get rid of jaxws-engine threads after processing asyncHandler?

    Hi,
    this question evolved from forum thread
    [t-5404241]
    In the current JAX-WS 2.1 (from Netbeans 6.7.1) implementation I see the following behaviour / bug:
    If you use the async Jax-WS API (AsyncHandler and Future) to send a SOAP request, there will be a thread named jaxws-engine-xx-thread and one unnamed
    thread generated by Jax-WS. Both threads stay running for 60 seconds after the soap response is processed.
    This leads to high memory consumption, if requests are made often.
    Is there a way to stop these threads?
    Stefan

    If it's asking for the original owner's credentials, you cannot "get rid" of it.
    http://support.apple.com/kb/PH13695

Maybe you are looking for

  • How to edit a QTVR file

    How can I edit a QTVR file and keep it as a QTVR file after editing.  I just need to crop the size of the rotating 3D object.

  • Itunes is not working in windows 7

    I have followed the instructions contained in..... iTunes for Windows Vista, Windows 7, or Windows 8: Fix unexpected quits or launch issues" I started it in safe mode and found that it works.  So I then followed the steps to remove third-party plug-i

  • How to display all authentication providers when creating a new user?

    I have configured active Directory with weblogic 10.3.1. Users and groups display correctly under the users and groups tab. When creating a new user only the defaultauthenticator provider is displayed in the drop-down selection. How do I get my activ

  • How to transfer parameters in jsp files

    what i want is : there is a jsp file named errorMsg.jsp, and in the file a variable msg which type is String is used, and the value of msg will be display on web browser. now, i want transfer a string to the errorMsg.jsp in another jsp file named try

  • Need package to call procedure in DBMS_JOB

    I have created a procedure that i what a DBMS_JOB to call at a schduelled time, but i don't know what DBMS package i can use to cat my procedure called ATREPORT.AT_DIV, I dnt knw the value for the what parameter DBMS_JOB.SUBMIT (job => :jobnumber ,wh