A thread wouldn't stop

Hi
Can anyone explain me this:
I have a thread running.
(A class ext. Thread impl. Runnable)
I wouldn't be able to stop the thread outside with doing:
mythread = null;
The thread would stop if I do:
mythread.stop();
Although, the compiler says that this method is deprecated.
How should I stop the thread then?

Btw, did you say you have a class that both extends Thread and implements Runnable? There is no reason to do that.
If you extend from Thread, then you start the thread by calling start() on an instance of that object.
If you implement Runnable, then you create a new Thread object and start this object:
Runnable target = new MyRunnable();
Thread thread = new Thread(target);
thread.start();

Similar Messages

  • I have a Mac Air. It said my start up disk was almost full and to delete files. I did but am not sure of what all I should delete. Then the color wheel wouldn't stop spinning so I just closed it. Now it won't open up at all. What can I do?

    I deleted files from my MacBook Air after it said my start up disk was almost full. It did several xs, then the color wheel wouldn't stop spinning, so I closed it. Then after a sufficient amount of time, I tried to start it up again, only now the Apple start up wheel just spins non stop and nothing else happens. How or what can I do to get my MacBook Air to work again, without having to take it in? Thanks so much!

    Backup your MBA then take it to Apple

  • I have several times tried to stop following a thread in the PDF's forum about security issues and i still keep getting flooded with emails from this thread. I used the action within the thread that says stop following but appears to have no effect I stil

    I have several times tried to stop following a thread in the PDF's forum about security issues and i still keep getting flooded with  emails from this thread. I used the action within the thread that says stop following but appears to have no effect I still keep  getting from 5 to 20 emails daily. Please help!!!!!!!

    This may be helpful: How do I disable email notifications?

  • JMF threads can not stop?

    My program is designed for two-way audio conference, but now I met a problem that there are some threads can not stop before I start some calls(maybe 100 times).How can I release this threads? please help me, thank you in advanced.
    RTPEventHandler
    JMF thread: com.sun.media.ProcessEngine@6b9fee[ com.sun.media.ProcessEngine@6b9fee ] ( configureThread)
    JMF thread: SendEventQueue: com.sun.media.processor.unknown.Handler
    JMF thread: SendEventQueue: com.sun.media.ProcessEngine
    JMF thread: com.sun.media.processor.unknown.Handler@1ca8dc7[ com.sun.media.processor.unknown.Handler@1ca8dc7 ] ( configureThread)
    JMF thread: com.sun.media.ProcessEngine@e1d29e[ com.sun.media.ProcessEngine@e1d29e ] ( configureThread)

    Hi TGreybeard,
    Have you looked at the [[Firefox keeps opening many tabs or windows]] Knowledge Base article? There is some good information in there that should help you resolve the issue.
    Hopefully this helps!

  • HT1414 phone started vibrating and wouldn't stop...now phone won't turn on

    phone started vibrating and wouldn't stop...now phone won't turn on

    See Here  >  http://support.apple.com/kb/HT1808
    You may need to try this More than Once...
    But... if the Device has been Modified... this will Not necessarily work.

  • 500GB DVR wouldn't stop resetting, now all recordings and scheduled series gone

    I saw similar threads on this topic, but not sure its the same or not. On 1/11, we were watching a recorded show and it started blinking out a few times, then reset itself. It came back on and then did it again a bit later. We rebooted by unplugging it for a few seconds and it came back.
    Then last night (1/12), we were watching a different recording, and the DVR reset itself. When it finished, it reset again. It continually did this around 5 times and then we unplugged it and plugged it back in. It still would just reset and reset. Unplugged again for longer. Repeat. Finally got it to stop resetting by leaving it unplugged while I ate dinner. Got it back to the place in the show we were watching, but the family had dispersed, so I turned it off. Later that night, I was watching from another STB (we have Home Media set up), and I saw the DVR said No recordings. Uh oh. I went to the DVR and turned it on and it showed No recordings and no series scheduled. I tried rebooting again a couple times and no luck. (It wasn't resetting anymore though!)
    So I called customer support. I had to get to Tier III before they would agree to send me a new box. Neither knows what happened. They tried resetting remotely and re-initializing and still No recordings. They say they are sending me out a new box.
    I'm not sure if we got a guide update or not. I don't remember seeing the "For HD press C", but I might have just missed it. Same with the captions options having all the options from the old system menu.
    The tech guy said to call billing after we receive the new DVR to see about compensation. If it was an update that caused this and not just a hard drive issue, I am super-**bleep**. In any case, I'm also **bleep** that they don't try to physically get the recordings back. No one wants to get data off a hard drive... Fortunately I had already watched the latest Downton Abbey!

    Though I don't know the size on my DVR, what you describe has been happening to me for three days now, too. Was annoying at first; now it's getting horrible, like every hour or two this happens.
    A new box is coming in the mail, but still, this is looking like a more common issue than it ought to be. I'm still in my 30 day "cancel" window for FiOS TV, and I'm about ready to switch right back at this stage.

  • Threads don't stop

    Hi all
    I have a class that extends Thread it gets to the end of the run method but the thread doesn't want to stop running. I though about using the stop() method, but it's depricated due to the fact that it can cause some problems with the program.
    I was wondering whether there is any other way to ensure that the thread stops. I have tried the return statement as the documentation suggest for a replacement to the stop() method.

    Is there any GUI business going on in this app?The only GUI business that is going on is the following set of calls just to get user input(in the test-app)
            JOptionPane.showMessageDialog(null, "Please specify the directory");
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            response = fileChooser.showOpenDialog(null);
    If you want the app to end when that thread is done,
    then the simplest thing is to just have main join that
    thread and then call System.exit(0) after the join.
    That's not always the safest route though. If the
    program is still running, it suggests there are other
    non-daemon threads still alive. In this case, they're
    presumably done with their work and just waiting for
    more. If so, then System.exit should be safe.The test-app should end when the thread is finished but when It gets imlemented into the live app, the live-app needs to be able to continue. This thread will be called multiple times at a regular interval during the life-time of the app. The live-app is a server app, thus it can go on indefinitely, and I don't need to have threads that don't stop running when they aren't required.

  • Thread: how to stop it?

    I'm new with thread and I don't understand some things about that.
    For example: when I create a Class that extends Thread class I must override the method run(), right? After when I call the method start() from the Class the thread runs in a never-ending cycle? How can I stop it?
    The example code:
    public class MyClass extends Thread {
        private int value;
        public MyClass() {
            value = 0;
        public void run() {
            value++;
    }Does the class continue to do the addition until it will throw an exception (when the max value of int type is reached)?
    Message was edited by:
    Lukyan

    Try to run it and see, no?Quoting myself ... I did not mean to be facetious. I really thought that actually running the code would be the clearest way of "seeing" the results. Better answers both before and after mine have provoked me to add the following:
    It is very common to code the actual guts of your "Thread" similar to this:
    private boolean run = true;
    public void run() {
      try {
        while (run) {
          doMethodA();
          doMethodB();
      } catch(InterruptedException ie) {
        doMethodC(); // or print the stack trace or something
    private void doMethodA() {
    private void doMethodB() {
      if ( "bad".equals(condition) )
        run = false;
    }

  • Javafx Multi Threading - How to stop a thread

    Hi,
    I'm working on a Javafx and Java based chat client. To avoid GUI freezing I have put all "business logic" calls to Java using the Runnable feature. Everyting works ok, but when for example disconnecting the chat client I would also like to stop this specifc thread, avoid building up unused threads. I have tried using .stop() but it looks like its being ignored.
    Here my code:
    main.fx:
    progressIndicator.visible = true;
            var listener = FXListener_interface_connection {
                        override function callback(errorCode, errorMessage): Void {
                            //do something
                            if (errorCode != 200) {
                                setIcn(errorMessage);
                            } else {
                                progressIndicator.visible = false;
                                imageView9.visible = true;
                                openMessageListener();
                                rosterListener();
                                var ooo = ScaleTransition {
                                            duration: 0.2s
                                            node: imageView9
                                            byX: 0.6 byY: 0.6
                                            repeatCount: 8 autoReverse: true
                                ooo.play();
            var connect = FXListener_connection {
                        listener: listener
                connect.start();listener_connection.fx:
    public class FXListener_connection extends JavaTaskBase {
        public var listener: FXListener_interface_connection;
        protected override function create() : RunnableFuture {
            new Java_callback_connection(listener);
    }connection_interface.java
    public interface FXListener_interface_connection {
        public void callback(Integer errorCode, String errorMessage);
    }connection_callback.java
    public class Java_callback_connection implements RunnableFuture {
        private static FXListener_interface_connection listener_interface_connection;
        public Java_callback_connection(FXListener_interface_connection listener_interface_connection) {
            this.listener_interface_connection = listener_interface_connection;
        @Override
        public void run() throws Exception {
            //call function xmpp_connect()
            static_variables.xmpp.xmpp_connect();
        public static void connection(final Integer errorCode, final String errorMessage) {
            Entry.deferAction(new Runnable() {
                @Override
                public void run() {
                    listener_interface_connection.callback(errorCode, errorMessage);
    }

    jdevel doesn't let me debug;
    public class ProgressBarModel extends BoundedRangeModel {
    BooleanValueWrapper stopFlag = new BooleanValueWrapper(false);
    BooleanValueWrapper stopFlag2 = new BooleanValueWrapper(false);
    IntValueWrapper value = new IntValueWrapper(0);
    Thread newProgress = null;
    Thread newProcessFile = null;
    public void start(ActionEvent e) {
    value.setValue(0);
    stopFlag.setValue(false);
    ProgressSimulator progressSimulator = new ProgressSimulator();
    newProgress = new Thread(progressSumulator);
    newProgress.start();
    ProcessFileThreadMe processFileThreadMe = new ProcessFileThreadMe();
    newProcessFile = new Thread(processFileThreadMe);
    newProcessFile.start();
    class ProgressUpdater implements Runnable
    public void run(){
    try
    System.out.println(" ProgressUpdater is running");
    //stop fag is true if it is set to true or if value is equals or greater
    //than maximum
    try { 
    stopFlag.setValue(stopFlag.getValue() == true? true : (value.getValue() < maximum? false:true));
    //run in loop until stop condition is met. Make sure system doesn't
    //fail if values are initially set to the same value
    while (!stopFlag.getValue() && value.getValue() != maximum) {
    newProgress.interrupt();
    newProgress = null;
    } catch(Exception e) {
    stopFlag.setValue(true);
    stopFlag2.setValue(true);
    class ProcessFileThreadMe implements Runnable
    public void run(){
    System.out.println(" ProcessFileThreadMe is running");
    try
    if(stopFlag2.getValue() == true) {
    // interrupt this thread
    // set it to null
    return;
    bean.persisit(value, stopFlag);
    newProcessFile.interrupt();
    newProcessFile = null;
    catch (Exception exc)
    stopFlag.setValue(true);
    stopFlag2.setValue(true);
    exc.printStackTrace();
    In the bean the v alue is incremented
    Edited by: user597294 on Jul 21, 2011 6:33 AM

  • Making a Thread that can stop itself

    I made a Thread this way;
    new Thread(new Runnable(){
    public void run(){
    }).start();
    how can I get this Thread to stop itself???

    What happens when an unstoppable thread hits an unmoveable block of code?I'd like to see that tested experementally at CERN :-)

  • Had to uninstall mobile device helper because a window kept coming up every 45 sec. saying it had stopped working. It wouldn't stop and online support said uninstall it.Well I did,now if I want to access iTunes store it pops up the iTunes has stop working

    Was advised to uninstall mobile device helper because a window kept popping up about every 45 seconds saying it had stopped working.Uninstalled it that took care of that problem,but now I have a new one.I can't access the iTunes store.Every time I click the store icon a window pops up saying iTunes has stopped working.Any suggestions anyone.

    anyone?
    *i've managed to download quicktime, but am still unable to download itunes. after reaching a certain point in downloading itunes, (about 1/3 of the way?) it stops at "copying files", and my computer freezes and i have to hold the power button in order to shut it off and do anything, or i get a popup asking me if i want to change something so itunes can finish downloading. i click "yes", but then the download stops completely and i get a message saying "itunes has finished downloading, but with errors" and it tells me to download it again.
    a popup from MobileServiceDevice keeps appearing as well, but it won't go away. the details are:
    Problem Event Name:    APPCRASH
      Application Name:    AppleMobileDeviceService.exe
      Application Version:    17.88.0.7
      Application Timestamp:    4e66ceff
      Fault Module Name:    kernel32.dll
      Fault Module Version:    6.0.6002.18005
      Fault Module Timestamp:    49e038c0
      Exception Code:    c06d007f
      Exception Offset:    0001e124
      OS Version:    6.0.6002.2.2.0.768.3
      Locale ID:    1033
      Additional Information 1:    fd00
      Additional Information 2:    ea6f5fe8924aaa756324d57f87834160
      Additional Information 3:    fd00
      Additional Information 4:    ea6f5fe8924aaa756324d57f87834160
    but the fault module name changes on me. sometimes it's kernel32.dll, and sometimes it's something else, and i've already tried using task manager /find str but it doesn't help.

  • Hello.  I just started using my iMac today, and I've already had a pushy intrusion from something called mackeeper.  They wouldn't stop texting me and downloading and wanted to charge me.  One of the reasons I bought Apple was because we wouldn't get this

    I called Apple support and they were very helpful.  Just concerned that my experience on my very first day was mackeeper telling me my computer was at critical levels and I needed protection.....for $90. 
    Nearly everyone I talked to asking about Apple products said they'd never experienced any spam/spy/ or intrusion....not sure what you'd call this. 
    Should I be concerned?

    MacKeeper and similar utilities are just scams that happen to use very aggressive marketing techniques. You may find that visiting certain, generally unscrupulous websites will leave persistent cookies on your system that cause these intrusive advertisements to appear more often than otherwise. Your best defense is to ignore them, don't visit unscrupulous websites, and set Safari's Preferences to block cookies and other website data "from third parties and advertisers". Find that setting in the Security pane.
    While you're there click the button "Remove All Website Data...". That will remove all cookies already present and should stop the popups. You will need to sign in again to any website for which signing in is required. If you don't want to remove all cookies then click Details... and remove only zeobit.com. For all I know MacKeeper may use others that are more obscurely named.
    Also, consider blocking pop-up windows in the Privacy pane. They are commonly used for advertisements you probably don't want. If you ever encounter a popup indicating it detected registry errors, that your Mac is infected with some ick, or that you won some prize, it is 100% fraudulent. Ignore it.

  • Killing an Updater Thread when I stop watch an JPanel

    Hi,
    Firstly this is proably really bad code convention. What I am wondering is how to fix my problem and perhaps some guidance on what to do instead, I am unsurre as to how to model an Updater thread on a JPanel. What I am doing is updating the Icons in JTree when the data changes, this happens continally so there is no start finish defined.
    I thought I could use isVisible() to work out when to terminate my updater thread, ut that doesnt seem to be the case. Any Ideas on what to do???
    Thanks a Mill,
    Anthony
    public class MyTreePane extends TreePane {
         private boolean start = true;
         public XRiskHistoTreePane() throws Exception {
              super();
          * This threads jobs is to scan the
         private void startScannerThread() {
              Runnable  r = new Runnable(){
                   public void run(){
                        int [] keys = getRiskKeys();
                        while(isVisible()){
                             for(int i = 0; i < keys.length; i++){
                                  try {
                                       Reporter rep = UpdateClient.getPosition(keys);
                                       PercentageIcon icon = null;     
                                       if(rep != null){
                                            int per = (int) rep.getPercentage();
                                            icon = new PercentageIcon(per);
                                       setImageIcon(keys[i], icon);
                                  } catch (Exception e) {
                                       e.printStackTrace();
              Thread t = new Thread(r);
              t.setName("Update Thread");
              t.start();
              t.setPriority(Thread.MIN_PRIORITY);
         public void paint(Graphics visible){
              super.paint(visible);
              if(start){
                   startScannerThread();
                   start = false;

    Hi,<br> Firstly this is proably really bad code convention. What I am wondering is how to fix my problem and perhaps some guidance on what to do instead, I am unsurre as to how to model an Updater thread on a JPanel. What I am doing is updating the Icons in JTree when the data changes, this happens continally so there is no start finish defined. I thought I could use isVisible() to work out when to terminate my updater thread, ut that doesnt seem to be the case. Any Ideas on what to do???
    <br>
    Thanks a Mill, Anthony
    <pre>
    public class XTreePane extends TreePane (which extends JPanel) {
         private boolean start = true;
         public XTreePane() throws Exception {
              super();
         * This threads jobs is to scan the
         private void startScannerThread() {
              Runnable r = new Runnable(){
                   public void run(){
                        int [] keys = getKeys();
                        while(isVisible()){
                             for(int i = 0; i < keys.length; i++){
                                  try {
                                       Reporter rep = UpdateClient.aggregationPosition(keys);
                                       PercentageIcon icon = null;     
                                       if(rep != null){
                                            int per = (int) rep.getPercentage();
                                            icon = new PercentageIcon(per);
                                       setImageIcon(keys[i], icon);
                                  } catch (Exception e) {
                                       e.printStackTrace();
              Thread t = new Thread(r);
              t.setName("Update Thread");
              t.start();
         public void paint(Graphics visible){
              super.paint(visible);
              if(start){
                   startScannerThread();
                   start = false;
    </pre>

  • New Socket takes too long / how to stop a Thread ?

    Hello to everyone,
    I have a problem that I have been hunting this ol' Sun website all day for a suitable answer, and have found people who have asked this same question and not gotten answers. Finally, with but a shred of hope left, I post...
    My really short version:
    A call to the Socket(InetAddress,int) constructor can take a very long time before it times out. How to limit the wait?
    My really detailed version:
    I have a GUI for which the user enters comm parameters, then the program does some I/O while the user waits (but there is a Cancel button for the Impatient), then the results are displayed. Here is quick pseudocode (which, by the way, worked great before there were Sockets in this program -- only serial ports):
    Main (GUI) thread:
         --> reset the stop request flag
         --> calls workerThread.start(), then brings up a Cancel dialog with a Cancel button (thus going to sleep)
         --> (awake by dialog closing -- dialog may have been closed by workerThread or by user)
         --> set stop request flag that worker thread checks (in case he's still alive)
         --> call workerThread.interrupt() (in case he's alive but asleep for some reason (???))
         --> call workerThread.join() to wait for worker thread to be dead (nothing to wait for if he's dead already)
         --> display worker thread's result data or "Cancelled..." information, whichever worker thread has set
    Worker thread:
         --> yield (to give main thread a chance to get the Cancel Dialog showing)
         --> do job, checking (every few code lines) that stop request flag is not set
         --> if stop request, stop and set cancelled flag for Main thread to handle
         --> if finish with no stop request, set result data for Main thread to handle
         --> take down Cancel Dialog (does nothing if not still up, takes down and wakes main thread if still up)
    THE PROBLEM: Worker thread's job involves doing IO, and it may need to instantiate a new Socket. If it is attempting to instantiate Socket with bad arguments, it can get stuck... The port int is hardcoded by the program, but the IPAddress must be typed by user.
    If the arguments to Socket(InetAddress, int) constructor contain a valid-but-not-in-use IP address, the worker thread will get stuck in the Socket constructor for a LONG time (I observed 1m:38s). There is nothing the Main thread can do to stop this wait?
    EVEN WORSE: If the user clicks the Cancel Button during this time, the dialog goes away soon/immediately, but then the GUI appears to be hanging (single-threaded look) until the long wait is over (after which the "Cancelled..." info is displayed).
    MY QUESTION: Is there nothing the Main thread can do to stop this wait?
    Your answers will be sincerely appreciated. Despite my hopeless attitude (see above), the folks at this forum really have yet to let me down ...
    /Mel

    http://developer.java.sun.com/developer/technicalArticles/Networking/timeouts/

  • Stopping a Thread in Infinite Loop

    I've read several articles on how to stop Threads, and all of them point to using Thread.interrupt(). The problem right now is what happens when the thread is in an infinite loop. For example:
    class A implements Runnable
        public void run()
            while(!Thread.currentThread().isInterrupted())
                  while(true);
    //in other class's main method:
    Thread a = new Thread(new A());
    a.start();
    a.interrupt();The a.interrupt() call only sets the isInterrupted flag in Thread, but it does not terminate the thread as a.stop() would. However, stop() throws a ThreadDeath exception that I would not want to have to deal with. Is there any way to stop this infinite loop thread safely?
    Thanks in advance!

    No need to get snitty. You certainly did not make clear that you are not a newbie at programming. Plenty of newbies who barely have a grasp of the language fundamentals post thread questions here. I thought I did address the question at hand. It seems I misunderstood what you were asking.
    The only way to safely stop that inner loop is like so: while (...) {
       while (!done) {
    }where done is volatile, or all access to it is sychronized on the same lock (meaning you'd sync the !done check above as well).
    If you can't do that, and it's stuck at while (true) and you can't modify the body of the inner loop to check done, then you're SOL.
    (I suppose it's conceivable that 1.6 or 6.0 or whatever it's called will introduce some new safe way to stop that thread, but I haven't heard anything about it.)

Maybe you are looking for