How to restart an interrupted thread ?

Hi All,
I have to stop a thread and then restart it after sometime. Since, stop() method is deprecated in jdk1.3 so, I m using interrupt() instead of stop() method. Can anyone please tell me , what does interrupting a thread exactly means? Does it termainates a thread completely or not?
Because , if I use thread.interrupt() and then thread.start() just after it, it raises exception java.lang.IllegalThreadStateException but still starts the thread.
Prime concern is how to stop and restart a thread without using stop() method??
Thanx and regards,
Shweta

You have to determine in the run method if the thread has been interrupted.
Usually like this
run()
while(!isInterrupted())
// code body
you could try this
boolean restart;
run()
while (true)
if (isInterrupted())
waitForRestart();
// code
waitForRestart()
restart = false;
while (!restart)
sleep(500);
restart(){restart = true;}

Similar Messages

  • How to restart ipad once battery has run down

    how to restart ipad once battery has run down

    The quickest way (and really the only way) to charge your iPad is with the included 10W USB Power Adapter. iPad will also charge, although more slowly, when attached to a computer with a high-power USB port (many recent Mac computers) or with an iPhone Power Adapter (5W). When attached to a computer via a standard USB port (most PCs or older Mac computers) iPad will charge very slowly (but iPad indicates not charging). Make sure your computer is on while charging iPad via USB. If iPad is connected to a computer that’s turned off or is in sleep or standby mode, the iPad battery will continue to drain.
    Apple recommends that once a month you let the iPad fully discharge & then recharge to 100%.
    How to Calibrate Your Mac, iPhone, or iPad Battery
    http://www.macblend.com/how-to-calibrate-your-mac-iphone-or-ipad-battery/
    At this link http://www.tomshardware.com/reviews/galaxy-tab-android-tablet,3014-11.html , tests show that the iPad 2 battery (25 watt-hours) will charge to 90% in 3 hours 1 minute. It will charge to 100% in 4 hours 2 minutes. The new iPad has a larger capacity battery (42 watt-hours), so using the 10W charger will obviously take longer. If you are using your iPad while charging, it will take even longer. It's best to turn your new iPad OFF and charge over night. Also look at The iPad's charging challenge explained http://www.macworld.com/article/1150356/ipadcharging.html
    Also, if you have a 3rd generation iPad, look at
    Apple: iPad Battery Nothing to Get Charged Up About
    http://allthingsd.com/20120327/apple-ipad-battery-nothing-to-get-charged-up-abou t/
    Apple Explains New iPad's Continued Charging Beyond 100% Battery Level
    http://www.macrumors.com/2012/03/27/apple-explains-new-ipads-continued-charging- beyond-100-battery-level/
    New iPad Takes Much Longer to Charge Than iPad 2
    http://www.iphonehacks.com/2012/03/new-ipad-takes-much-longer-to-charge-than-ipa d-2.html
    Apple Batteries - iPad http://www.apple.com/batteries/ipad.html
    Extend iPad Battery Life (Look at pjl123 comment)
    https://discussions.apple.com/thread/3921324?tstart=30
    New iPad Slow to Recharge, Barely Charges During Use
    http://www.pcworld.com/article/252326/new_ipad_slow_to_recharge_barely_charges_d uring_use.html
    Tips About Charging for New iPad 3
    http://goodscool-electronics.blogspot.com/2012/04/tips-about-charging-for-new-ip ad-3.html
    Prolong battery lifespan for iPad / iPad 2 / iPad 3: charging tips
    http://thehowto.wikidot.com/prolong-battery-lifespan-for-ipad
    In rare instances when using the Camera Connection Kit, you may notice that iPad does not charge after using the Camera Connection Kit. Disconnecting and reconnecting the iPad from the charger will resolve this issue.
     Cheers, Tom

  • I put my computer to hibernate and i stoped to download lion. How i restart the download?

    I put my computer to hibernate and i stoped to download lion. How i restart the download?

    Read here >  Mac App Store: How to resume interrupted downloads

  • How Can I stop my thread?

    Hi!
    I'm developing an application of computacional geometry. It consist on a JFrame where I put some components like a JToolBar, a JTextArea, etc, and a JPanel. When the JPanel it's painted, there are a button that runs the JPanel in a new Thread.
    The problem is that I have another button to stop the thread, but I can't stop it completely if it is in a I/O operation.
    Here is the code of the run() method:
    public void run()
    Thread thisThread = Thread.currentThread();
    while (kicker == thisThread)
    if (runMode)
    lhull.removeAllElements();
         hull.removeAllElements();
    GrahamScan();
    runMode = false;
    aFrame.doneButton.setEnabled(true);
    stop();
    I stop the thread, but when it's in the GrahamScan() method, it continues painting things in the panel.
    How can I stop the thread completely?
    Thanxs in advance!!

    What's the matter with my line separators and my code indentation?
    Try to use yourThread.interrupt() at your button push event, and this code;
    public void run()
    Thread thisThread = Thread.currentThread();
    try {
    while (kicker == thisThread)
    if (runMode)
    lhull.removeAllElements();
    hull.removeAllElements();
    GrahamScan();
    runMode = false;
    aFrame.doneButton.setEnabled(true);
    stop();
    } catch (InterruptedException iEx){

  • How to restart base station from airport utility? I used to be able to do it remotely  I currently use a Mac Pro 10.8.4 and have a time machine for wireless 6.3 (630.34). Sometimes I cannot connect to the internet and use network preferences to diagnose t

    How to restart base station from airport utility? I used to be able to do it remotely
    I currently use a Mac Pro 10.8.4 and have a time machine for wireless 6.3 (630.34). Sometimes I cannot connect to the internet and use network preferences to diagnose the issue. This results in being told to restart the wireless. The airport utility includes the drop down option of restarting but is not clickable so I can't choose it.
    With my prior macbook and same time capsule, etc  if i had problems connecting to the internet I would run network diagnostics to help out. This included clicking on the airport utility ---> base station --> restart. This worked most of the time.
    Bottom line, is there something I am missing in not being able to restart the wi-fi remotely? ]
    Thanks in advance

    You are likely forgetting a step.
    Open AirPort Utility
    Click on the Time Capsule icon
    Click Edit in the small window that appears
    Now click the Base Station menu.....top of the screen....not the Base Station "tab" in the center of the screen
    Click Restart

  • How to terminate a java thread from c++ code?

    Hi,
    I made a screensaver which loads a jvm, forks a thread running a java class, wait until user's action(i.e. mouse move/click keyboard input), then terminate the java thread.
    However, I met a problem, How to terminate a running java thread from c++ code?
    Here is my code, but it does not work: (even after the terminate is called, jvm throws an error)
    JNIEnv* env;
    JavaVM* jvm;
    HANDLE hThread; //handle for the startThread
    unsigned __stdcall startThread(void *arg)
         jclass cls;
         jmethodID mainId;
         jint          res;
         int threadNum = (int)arg;
         res = jvm->AttachCurrentThread((void**)&env, NULL);
    cls = env->FindClass( MAIN_CLASS);
         mainId = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
         // setup the parameters to pass to main()
         jstring str;
         jobjectArray args;
         int i=0;
         args = env->NewObjectArray(1, env->FindClass("java/lang/String"), 0); //only one input parameters
         str = env->NewStringUTF("localhost");
         env->SetObjectArrayElement(args, 0, str);
         env->CallStaticVoidMethod(cls, mainId, args); // call main()      
         if (env->ExceptionOccurred()) {
                   env->ExceptionDescribe();
         return TRUE;
    Here is the main method:
    First create the jvm and load the thread. then tries to terminate the thread, but failed here
    switch (msg)
    { case WM_CREATE:
              JavaVMOption options[NUMBEROFOPTIONS];
              JavaVMInitArgs vmargs;     
              jint rc;
              vmargs.version = JNI_VERSION_1_4; /* version 1.4 */
              vmargs.options = options;
              vmargs.nOptions = NUMBEROFOPTIONS;
              vmargs.ignoreUnrecognized = JNI_FALSE;          
              rc=JNI_CreateJavaVM( &jvm, (void **)&env, &vmargs ); /* create JVM */
              /* We pass the thread number as the argument to the invoked thread */
              unsigned int threadId = -1;
              // to initialize a thread-safe C runtime library
              hThread = (HANDLE)_beginthreadex(NULL, 0, &startThread, NULL, 0, &threadId );
    } break;
    case (WM_DESTROY):
              CloseHandle( hThread );
              jvm->DestroyJavaVM(); /* kill JVM */
              Debug("Destroy Java Virtual Machine\n");
    }break;
    Note, after the thread "startThread" runs, it has an infinite loop and will not terminate, until the user clicks to terminate.(I didn't call jvm->DetachCurrentThread();_endthreadex(0); in the "startThread" because the java thread will not terminate by itself)
    Thus, the only way to terminate the thread is to call closehandle(hthread) in the main thread, which may cause jvm to throw an error.
    Do you know how to terminate a java thread safely???
    Thanks a lot

    Assuming that your java thread is in a loop of some kind. Such as
    int i=1; /* I tried using a boolean, I just could not get my C++ env, to change this value. So i decided to use an int */
    run {
    while(i)
    isdfjsdfj
    void seti()
    i=0
    So, B/4, i call destroyVM in my C++ code, i call this seti(). so the loop terminates, therefore my thread finishes executing and ends.
    Hope this helps
    tola.

  • How to make the main() thread wait?

    I would like to know how to make the main() thread wait for another thread?If I use wait() method in main() method it says "non-static method wait() cannot be referenced from a static context",since main()
    is static.

    Here is an example how you may wait for a Thread in the main -
    but be careful, this is no real OO:
    public class WaitMain {
    // this is the thread class - you may also create
    // a runnable - I use a inner class to
    // keep my example simple
         public static class ThreadWait extends Thread{
              public void doSomething(){
                   synchronized(syncObject){
                        System.out.println("Do Something");
                        syncObject.notify();
              public void run(){
                   // sleep 10 seconds - this is
                   // a placeholder to do something in the thread
                   try{
                        sleep(10000);
                        doSomething();
                        sleep(10000);
                   catch(InterruptedException exc){
    // this is the object we wait for -
    // it is just a synchronizer, nothing else
         private static Object syncObject = new Object();
         public static void main(String[] args) {
              System.out.println("This will start a thread and wait for \"doSomething\"");
              ThreadWait t= new ThreadWait();
              t.start();
              synchronized(syncObject){
                   try{
    // this will wait for the notify
                        syncObject.wait();
                        System.out.println("The doSomething is now over!");
                   catch(InterruptedException exc){
              // do your stuff

  • How do i run two threads with different sleep times?

    How do i run two threads with different sleep times?
    Ive got thread A and thread B, they both update a jpanel.
    They both start when i press the start button.
    However thread A updates every 250ms and thread B updates every 1000ms. i cant just run them both at 250ms becuase this will mess it up.
    So for every four runs of thread A i want thread b to only be run once
    Does anyone know how to do this?
    Thanks, Ant...

    ok, ive done it but now i cant stop it!
    ive added buttons to start and stop, the start button works but the stop button doesnt. why doesnt "t.stop();" work?
        public void run() {
            while(t == Thread.currentThread()) {
                System.out.println("No " + t.getName());
                if (t.getName().equals("1")){
                    try {
                        t.sleep(1000); // in milliseconds
                    } catch (InterruptedException e) {}
                } else{
                    try {
                        t.sleep(250); // in milliseconds
                    } catch (InterruptedException e) {}
        }

  • How do i copy a thread in text messages and copy into a note pad app?

    how do i copy a thread in text messages and copy into a note pad app?

    Tap and hold a bubble, and select More. Put a checkmark beside each bubble you want to copy, then hit the arrow at bottom right. This will open a new message with the copied text in the text entry box. You can copy all of this and paste into Notes, but you lose who it came from unless you edit that in yourself.
    You can also take screenshots of each window of text bubbles.

  • Outbound process red flag - how to restart?!

    Hi, well i tried in a previous post to get help but i guess it was a little misunderstanding.
    I have a well processed message but it's not being send to target system, so i get a red flag on column outbound status in SXI_MONI. It's like a system is not available but in this case it is.
    It is File to IDoc Scenario and be sure that i already checked SM59, SX1, SX2 and so on.
    Funny thing is that sometimes message is send properly - when CC read one file - but when it has to read >1 outbound status will be set to error for each message!
    has somebody any clue on this issue?!
    br!!

    Hi,
    it's a FILE2IDoc Scenario i am getting no error at all except of the red flag for outbound process. In detal-view of the message nothing is reported an even the CC-Monitoring is showing nothing because IDoc-Adapter is not part of the Adapter-Engine.
    That's the problem! Because a target systems is connected via VPN to the gateway of the XI. And when the VPN is not active, the message is not being transmitted. But in XI i connat restart it when VPN-Tunnel is active again.
    Any clue on how to restart?!
    br

  • How to restart an workflow if ended in error at SEND Mail step.

    Hello All
          I am facing some problem in restarting the error workflow.
    Issue is:
       Workflow ended in error at the mail notification step, since the mail id is not filled into the container so there is no address (mail id) and ended in error.
       How to restart these kinds of workflow in the system?, we have tried to change the container value by assigning mail id and restarted the workflow but still went into error.
    Is it possible to restart an workflow which ended in error other than rule resolution.
    Regards
    Anand KS

    I think you went in the write approach. I think you have to change the container properly by populating the ADDRESSTRING container element. Also check whether type of email recipient in your container is et to Email.
    Thanks
    Arghadip

  • How can I close core thread in ThreadPoolExecutor?

    If I use unbounded LinkedBlockingQueue in ThreadPoolExecutor and set the core pool size to 5. When more than 5 tasks are submitted, there will be 5 threads created to handle the request. After finish, these threads will not be closed. How can I make the threads in core pool be closed when finishing their job? I couldn't use maximum pool for that I do need an unbounded queue.

    If you really want that functionality, set the core pool size to 0, the maximum pool size to 5 or greater, and the keepAliveTime to 0L. This will remove excess threads as soon as their tasks have completed.
    It's very wasteful though if you plan on executing the tasks repeatedly to create new threads everytime you submit a task. One of the benefits of using a thread executor is not having to construct and start a Thread object everytime you run a task.
    Brushfire,

  • How to restart WorkItem if the status is completed

    Hello,
    Due to my mistake in PRD not in DEV i changed the WI status from started to completed.
    Now i have 110 WI affected and i dont know how to restart them, or make them finish normaly the right path.
    In the LOG i can see: Execution was ignored (work item has final status)
    Area: SWF_RUN
    Msg: 568
    Regards
    Laurynas Prikockis
    Edited by: Laurynas Prikockis on Apr 15, 2009 7:59 AM

    Resetting the status of a completed workitem? I think it is not possible , because you can reset the status of a workitem which is in in process state to ready state or the workitem which is in error state( May be not sure) but the status of completed workitem , not possible, because the workitem will not be in any of the users inbox.
    But will let you  know , if there is any possiblity
    Check this error when I tried to reset the status of workitem which is completed by using the FM
    SAP_WAPI_SET_WORKITEM_STATUS
    Status change from COMPLETED to READY is not allowed/possible

  • HT4759 my ipad is disabled.how to restart

    due to wrong passcod my i pad is disabled..please advice or suggest to how to restart my i pad

    Hi gibachonga,
    Welcome to the Support Communities!
    The article below may be able to help you with this.
    iOS: Forgotten passcode or device disabled after entering wrong passcode
    http://support.apple.com/kb/ht1212
    Cheers,
    - Judy

  • How to restart the J2EE Engine

    I ran a couple tests the other day, and the next time I looked the J2EE Engine was down.  (Could not send or receive PTP messages to it).
    When I brought up the J2EE Engine Administrator, it put upt the following help box:
    <b>Unable to lookup connection default
    http:host1:8101/msgserver/text/login returned empty list of connection parameters</b>
    I had to reinstall to get it to work.
    Does anyone know how to restart the J2EE engine ?
    Thanks, John

    Hi,
    judging by the URL given in the error message (which is a URL that queries the message server), your engine must be of 6.40 version. Well, on 6.40 you should have the SAP Management Console (SAP MMC) that you can open and start the engine from. TO open it, go to Start -> Programs -> SAP Management Console. Inside, locate your SAP System, right-click on it and select Start.
    That's it.
    Just for a reference, <a href="http://help.sap.com/saphelp_nw04/helpdata/en/9b/dd7277f3e64ecba59f7fbac7edd2fe/frameset.htm">this</a> page contains also some screenshots of the MMC.

Maybe you are looking for

  • Why app world does not prompt when exitting while installation is going on.

    When I install any apps from apps world, why it does not promt when installing anything, This is bcz it stops the download . Its frustrating when you have to again download it .

  • Strange blanks

    hi! i have a strange problem. if i read from mysql ( datatype TEXT ) and write it into a textarea ( html ), there are a tab and two blanks inserted before the text?! if i store again, they add up to two tabs and four blanks.....ect. but if i take the

  • Solution Directory - Business Scenario

    Hello, I am trying to find the job management - job monitoring scenario under SAP ERP. I had everything set up under SAP ECC and still can see it there. But now that I switched my systems to SAP ERP, I would like to select it there, but cannot find i

  • 2 TB HP External Reviews?

    I bought a HP External Drive to replace a WD "green" drive that I think must have died in the last couple of days. http://www.officemax.com/technology/drives-memory-storage/hard-drives-usb-drives /external-hard-drives/product-prod3490334 I was going

  • Moving Backup is extremely slow

    Hello: Until now I used a 1 TByte firewire drive from La Cie to backup my iMac 24". Now I bought a 2TByte Time Caspule, set it up successfully and wanted to move the backup from the La Cie to the TC. I followed these instructions: http://web.me.com/p