Cannot stop this thread...

Hello, I have the following code:boolean kill = false;
public void go() {
   while (!kill) {
        sleep(3000);
        //do stuff.
public void stopThread() {
    kill = true;
}This code doesn't stop it. I cannot seem to stop this thread with the boolean variable. I think its because I have the thread asleep but I'm not sure. How can you stop a thread that sleeps for a period of time?
Thanks.

Here's my code: class CreateGui {
Vector<Thread> threads = new Vector<Thread>();
//lots of stuff here...
public void start() {
     Runnable runner;
runner = new RunThreads();
     Thread t = new Thread(runner);
     t.setName(_code);
     t.start();
     threads.add(t);
public void stop() {
     RunThreads r = new RunThreads();     
     r.stopThread();     
class RunThreads implements Runnable {     
     boolean kill = false; 
public void run() {
     go();
public void go() {
   while (!kill) {
     try {
     Thread.sleep(3000); .
     } //try          
     catch (InterruptedException ex) {
     ex.printStackTrace(); }
         //do stuff here...     
          } //while
} //method go
public void stopThread() {
     kill = true;
}The user clicks a button to start a thread, and then clicks another button to stop the thread. With this program I am supposed to have up to 26 threads running at once. I know I may not be doing things totally correctly, but that is what I'm trying to accomplish. I can take the harshest criticism: )

Similar Messages

  • How to remove a black border box that continously tabs to each field automatically till end of web page; restarts to top of page, cannot stop this box. Scroll bar cannot controlled with mouse, returns auto to top of scroll slide, never remaining at bottom

    how to remove a black border box that continously tabs to each field automatically till end of web page; restarts to top of page, cannot stop this box. Scroll bar cannot be controlled with mouse, scroll bar returns automatically to the top of scroll slide every time I move the bar to the bottom of the scale.  Also, there's a rectangular text box (with black background and white text) that is always on the desktop that emulates a typed text, HTML, or cmd function.

    cjuan1morb4ulv wrote:
    how to remove a black border box that continously tabs to each field automatically till end of web page; restarts to top of page, cannot stop this box. Scroll bar cannot be controlled with mouse, scroll bar returns automatically to the top of scroll slide every time I move the bar to the bottom of the scale.  Also, there's a rectangular text box (with black background and white text) that is always on the desktop that emulates a typed text, HTML, or cmd function.
    The first two problems (box cycling from element to element on page, scroll bar returning to top) can be caused by a stuck (or defective) Tab key on the keyboard. Such damage can be caused by a liquid spill; just one tiny droplet is enough to short a wafer switch under one key.
    The last issue (black box, white text - sounds sorta like a debugger window) I haven't seen, but could be caused by something similar.
    To check for that, try using a different keyboard. If you're using a wireless keyboard, turn it off and see if the oddities stop.

  • Hi, on my fathers pc sometimes when downloading multiple tabs start opening and I cannot stop this happening. Could anybody please help me?

    Hi, on my fathers pc sometimes when downloading multiple tabs start opening and I cannot stop this happening. Could anybody please help me? for example, trying to download TomTom Start 25 user manual

    You get that problem if you select the Firefox program to handle a file if you get an "open with" dialog.
    *https://support.mozilla.com/kb/Firefox+keeps+opening+many+tabs+or+windows

  • Since downloading Firefox when I go on the Internet Internet Explorer pops up with a message - IE cannot open the webpage - Favorit. I have tried everything but cannot stop this happening. Any suggestions? Thanks. I am running Vista.

    Since downloading Firefox when I go on the Internet Internet Explorer pops up with a message - IE cannot open the webpage - Favorit. I have tried everything but cannot stop this happening. Any suggestions? Thanks. I am running Vista.

    The exact same things happend to me!! how frustrating! ive reinstalld it soooo many times and quicktime seperatly too as i have had so many different error messages including something to do with quicktime, i dont know what to do but as you said my ipod is useless with out itunes! if anyone works this out let us know! thanks alot x

  • HT5129 I cannot stop this transfer, even though I have already transferred all of my movies and photos; what's more, iPhoto goes into freeze mode. Help!?

    Nightmare scenario, MobileMe is transferring photos, even though I've already made the transfer and freezing iPhoto at the same time. I cannot stop the transfer. Help!!

    Quit - or force quit - iPhoto.
    Then relaunch. When the "Mobile Me has ended" panel appears press the "Learn More" button, not the "o.k." button.
    Then you should be able to open the Preferences in iPhoto and and open the "Accounts" panel. Remove "Mobile Me" from the iPhoto Accounts.
    Then also open the System preferences > Mobile Me panel and sign out of Mobile Me.
    If this does not work, try to disconnect from the Internet before you launch iPhoto again.
    Regards
    Léonie

  • How could stop this thread that calls an externall function ?

    Hi all.
    i need an help about syncronization of two thread.
    the first one is smt like that
    Thread t = new Thread(new Runnable() {
                   public void run() {
                        long startTime = System.currentTimeMillis();
                        while (System.currentTimeMillis() - startTime < lifetime) {
                             if (c.dynamic) {                    
                                  c.adjustLayout();
                             c.repaint();
                             try {
                                  Thread.sleep(delayMillis);
                             catch (InterruptedException ex) {
                                  // ignore
              t.start();where c.adjustLayout(); & c.repaint(); are syncronized over a astructure called G using syncronized(G)
    now the second thread is:
         Thread t = new Thread(new Runnable() {
                   public void run() {
                        long startTime = System.currentTimeMillis();
                        while (System.currentTimeMillis() - startTime < lifetime) {
                             if (c.updateVisible) {
                                  c.updateVisibleGraph();
                             try {
                                  Thread.sleep(delayMillis);
                                  Thread.yield();
                             catch (InterruptedException ex) {
                                  // ignore
              });where the function c.updateVisibleGraph(); is syncronized over G as well. the problem is that this function, takes seconds, and block thread A and B (both of them ar suyncronized, so if B is running A cannot run).
    how can i stop c.updateVisibleGraph(); in the middle of the exectuion or each 50ms.
    is this possible?
    thanks
    Edited by: ELStefen on 26-ago-2010 16.08
    Edited by: ELStefen on 26-ago-2010 16.11

    isocdev_mb wrote:
    Using a synchronized-block is not designed to give up the lock for little while, it holds the lock until the block ends. Your requirement needs a far more fine-grained approach, quite different from your sketched implementation.
    It would involve quite an amount of guessing of what's behind the G and c your mentioning to suggest a way out. Please elaborate on what you're trying to achieve so that we can suggest how to do that...
    P.S. this forum likes problems to come with a simple working example, which you did not provide and a description of what you'd like to achieve, some context.as i thought, damn.
    Well give a working example is quite complex for the time being. Is a big project and take out this part is quite complex. But i can explain the goal.
    Practically there's a Graph (G)
    this graph is used by 2 thread, one is the update the edges and vertices, adding and removing them. the other one thread is the painter of the graph.
    the problem is when the first thread is updating the structure of G, sometimes this operation takes time (seconds) and being synchronized on G it blocks the paint thread as well.
    the thing that i would like to have is keep the painting working each tot millisecond. the updating thread works when necessary. if the update operation takes to long, it has to be stopped in the middle (and it has to restart after the paint) in a way that the paint thread can be executed.
    as the code is, and as you said, synchronizing the entire block code cannot works as i want.
    is this more clear? any clue about how can i solve this?
    many thanks
    Edited by: ELStefen on 27-ago-2010 12.43

  • When in Outlook I constantly get Firefox file download prompts. I cannot stop this - please help.

    The file downloads are always different but have the following pattern of digits: 8-4-4-11.
    If I save the file (they seem to range in size from 6 kb to 30 kb)
    there is nothing there when I open it.

    Hi ljwayne,
    Please make sure that it is not an add on by restarting in Safe Mode: [[Troubleshoot Firefox issues using Safe Mode]]
    If this continues you can right click on the window and click on "Page Info". From there you can manage the permissions of pop ups from that site.
    If it is already blocked please do a virus scan to make sure there is not a virus or adware. For mac I used to use bitdefender.
    Last troubleshooting I can think of: try a new profile. [[Use the Profile Manager to create and remove Firefox profiles]]

  • I have Adobe Reader on the ipad and it is continuously installing an update I cannot stop this

    I have Adobe Reader on the ipad It is continually

    On your iPad Home screen, you can delete the Adobe Reader icon. Press and hold down on the icon until you see the icons "shaking", then press the X on the Reader icon to delete it.
    (If you wish, you could reinstall the app from the App Store.)

  • Cannot Stop Thread with ServerSocket

    Hi
    I have a problem with a Thread that runs a ServerSocket. I want to stop this Thread from the main-application:
    Thread class:
    Constructor:
    serverSocket = new ServerSocket(address, port);
    public void run() {...
    while (true) { ....
    clientSocket = serverSocket.accept();
    I want to do the following in the main-application:
    because I want to set up a Thread with a new ServerSocket:
    myThread = null; // to stop the Thread, I also have tried to interrupt without success
    myThread = new Thread(); // => BindException and serverSocket == null;
    I always catch a BindException and in the Thread-Constructor the serverSocket is set null !
    How can I avoid this?
    I need to get a new serverSocket!!
    Can anyone help me?
    thanks, walter

    Thank's for reply: The problem I have is the following: My domain has a dynamic IP, so after the IP changes the s.accept() does not work any more!
    try // Point 1 *)
    ServerSocket s = new ServerSocket(portNumber);
    for(;;)     
    Socket incoming = s.accept(); // does not work after IP changes
    new ThreadedEchoHandler(incoming, i).start();
    So I have to detect that the IP has changed and have to start again at Point 1
    How can I do this?
    thx walter

  • How to stop a threads that makes I/O calls ?

    Hi,
    I've a business method that calls a Stored Procedure and makes lots of calculations. This method works inside its own thread, because I do not want to stop the GUI from accepting user actions.
    My problem is : this method may take from 5 minutes to 1 hour to process, depending on the size of the input. Sometimes, for any reason at all, the user may want to stop this execution (pressing a button on the GUI). How can I safely stop the thread ?
    I know I should not use stop() and suspend() because they are deprecated. And I do not use loops (remember it calls only a StoredProcedure that makes all processing), so I cannot use a variable nor interrupt(), because they do not work.
    Do you know any other way to stop this thread's execution ? By the way destroy() is not implemented.
    Thanks and regards.
    Bruno

    Are you saying that the 5 minutes to an hour is all spent in the stored procedure?
    If so the only real solution is to kill the statement - I'm not sure how the DB will handle that, but it will certainly free up your cycles.
    To do that without violating encapsulation, you just need to keep a reference to an object that knows something about the DB connection - you don't have to actually pass around the JDBC objects.
    Consider an object like this:
    public class DoLongProcedure {
       private Statement dbStatement;
       public double doLongCalculation() {
          dbStatement.execute(...);
          // etc
       public void interruptCalculation() {
          dbStatement.close();
    }You create an instance of this object and call its doLongCalculation() method to start everything. You have a reference to this object somewhere, because you are waiting for a response. When the user wants to cancel the process you just call the interruptCalculation() method.
    You have not violated your separation of functionality - if you find a new way to stop the process without killing the statement later, you just reimplement that method.

  • Problems stopping a Thread

    HI all
    I'm %$&�* with this problem!!! I'm 3 hours trying to solve it!
    I have a BufferedReader associated with a socket this way
    BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));So I read from the socket this way:
    String result = in.readLine();The problem is that the Thread that reads from the socket keeps stuck at the line String result = in.readLine(); because it waits for
    the stream to provide content.
    I need to stop this thread! so I read the reference and found a method called shutdownInput(); from Socket class. But its not working! when I trigger shutdownInput() it is not releasing my thread to end!
    what do I do?
    thank you all

    You have several options.
    You could use setSoTimeout to specify how long to block. When the block is finished you could check a semaphore variable to sse if you should quit or retry.
    You could call close directly on the Socket.
    You should explore the first option.

  • Cannot stop getting email threads from this forum.

    Had a problem with Safari crashing. Posted the problem and even though people tried to help the problem never got fixed.
    Since then i get a notification copy of every email of every problem sent to the person I posted the question to.
    Changed settings to no avail. I get 20-40 emails from this forum every day and cannot stop it!
    What to do? Thanks.

    Next time you see one of those emails, click vew full discussion. Once there sign in, then in the upper right hand conner click "stop email notification"

  • Cannot stop memory monitor thread

    Hi All,
    I am getting the following error intermittently in a dataflow which has degree of parallelism = 8.
    22943 0 SYS-170111 27/11/2009 12:22:05 |SubDataflow DF_Conform_ISI_Person_Match_Prep_1_9
    22943 0 SYS-170111 27/11/2009 12:22:05 Cannot stop memory monitor thread: <RWThreadImp::terminate - No thread is active within the runnable>
    Any ideas as to the cause ?
    Thanks,
    Eric Jones.

    We are having the same issue.
    According to ADAPT00890818, this issue should be resolved in 12.0.0. We are currently running with version 12.2.2.3.
    Please advice.

  • SYS-170111 - Cannot stop memory monitor thread: RWThreadImp::terminate -

    Hi Experts,
                  WE have this warning in pretty much every job in production. But the warnings are not specific to certain jobs they might occur one day and not the other day.
    Cannot stop memory monitor thread: <RWThreadImp::terminate - No thread is active within the runnable>.
    I know looking at the release notes this issue was fixed in 3.0 (12.0.0), we are using 3.2 (12.2.0) and having the same issues. The job server is on a linux 64 bit. I have not seen this issue in any of our windows job server. Is this bug specific to linux or is there a resolution for this.
    Appreciate your help in advance.
    Thanks
    AJ
    Edited by: alangilbi on Sep 28, 2011 5:17 PM

    Hi, AJ.
    As can be seen in the KBA 1455412 this is a known behavior.
    "As a result of fixing the problem identified in ADAPT 00890818 in release 12.0.0.0, this message is displayed by design. If there is really a problem in stopping the memory monitor thread an exception is thrown and an error message is logged.
    Background:
    In the memory monitor's shutdown logic, once it tells the monitor thread to shutdown it waits for the thread to terminate but only for 10 seconds. It could be that at this same time the wait expired when the thread actually terminates. So when this happens in the shutdown logic we force terminate the thread. Since there is no active thread anymore the terminate call throws an exception and then we catch it and then throws the error for the job."
    You can just ignore this warning.
    Leo.

  • I downloaded TunesGoWatch by Wondershare. I deleted the app. Every time I turn on my computer I get a popup saying "TunesGoWatch" can't be opened because the identity of the developer cannot be confirmed. I deleted the app, how do I stop this popup?

    I downloaded TunesGoWatch by Wondershare. I deleted the app. Every time I turn on my computer I get a popup saying "TunesGoWatch can't be opened because the identity of the developer cannot be confirmed." I deleted the app, how do I stop this popup?  Your help is truly appreciated

    First:
     (Apple menu) > System Preferences > Users & Groups > select your account > Login Items.
    Determine if that program appears in that list. If it does, select it and then remove it from Login Items with the "–" (minus) button.
    Next:
    Select the entire line that follows (triple-click to select it), then control-click, and from the contextual menu that appears, select Services > Open:
    /Library/StartupItems/
    If the program or an alias to it appears in that folder, drag it to the Trash.
    Next:
    When you log out or shut down your Mac, de-select the checkbox that begins with the words "Reopen windows... "

Maybe you are looking for

  • My album artwork does not match the song in my playlists

    After making playlists with music purchased from itunes in my music app, the art work does not match the title of the song / album. How can I fix this problem?

  • Judder in flash video playback

    I'm having this weird random judder issue when viewing video playback using the flash player (e.g. youtube).  The judder is very noticeable on 2d scrolling videos such as this http://www.youtube.com/watch?v=VAdHJYUjeVo&feature=g-all-u#t=10m40s.  I ha

  • Thumbnails in one project "Media Offline" but Canvass OK

    One of my projects now has replaced the thumbnails in some of the clips in the timeline with red and "Media Offline. However, the media is online in the browser, and viewing the clips in the Viewer and playing the Timeline in the canvas perform norma

  • If statements in a constructor...

    Can I just add if statements into a constructor the same way I would put them in a method? Or do I have to do something special to them?

  • Document Count

    Hello Gurus, I have a requirement to display the document count of Document numbers. I am querying on an infoset, which has a Cube and an DSO. The cube contains header data. Hence there is 1 count against the document number. The DSO holds item detai