Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By gimbal2

Thread: How to Stop this Thread

  1. #1
    Sarmad.as is offline Member
    Join Date
    Nov 2013
    Posts
    27
    Rep Power
    0

    Default How to Stop this Thread

    in for loop break the loop if volatail flag is false but it dose not break the loop whyy please Help?
    Java Code:
    //how to stop this thread
    public void stoptd(){
    running = false;
    }
    @Override
    public void run(){
    
    b1.setEnabled(false);
    
    Element link;
    Element src;
    Element imports;
    int linknum = 0;
    int i = 0;
    double test ;
    
    
    for(int j = 0; j < total_size; j++){
    
    
    
    if(linkf == true && j < linkss.size()){
    link = linkss.get(j);
    DownloadPage(link,j);
    linknum++;
    }
    else if(j == 0)
    {
    total_size -= linkss.size();
    }
    if(sublinkf == true && j < Imports.size() ){
    imports = Imports.get(j);
    DownloadImports(imports);
    }
    else if( j == 0)
    {
    total_size -= Imports.size();
    }
    if(imagesf == true && j < media.size()){
    src = media.get(j);
    
    DownloadImg(src);
    }
    else if(j == 0){
    total_size -= media.size();
    }
    if(running = false){ // break the loop if the volitail flag is false
    break;
    }
    test = ((float)j/total_size)*100;
    String values = String.format("%.2f",test);
    values = values+"%";
    
    
    table.setValueAt(values,tblrow,1);
    
    
    }
    JOptionPane.showMessageDialog(null,"Thread Stoped");
    //stop method
    private void b3ActionPerformed(java.awt.event.ActionEvent evt) {
    downloadpage d2;
    d2 = Tarray.get(0);
    d2.stoptd();
    
    
    }

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,600
    Rep Power
    5

    Default Re: How to Stop this Thread

    You have running = false. It should be running == false. Or

    if (!running) {
    break;
    }

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: How to Stop this Thread

    Yeah, that wouldn't even compile, so of course the loop never stops...
    Get in the habit of using standard Java naming conventions!

  4. #4
    Sarmad.as is offline Member
    Join Date
    Nov 2013
    Posts
    27
    Rep Power
    0

    Default Re: How to Stop this Thread

    Quote Originally Posted by jim829 View Post
    You have running = false. It should be running == false. Or

    if (!running) {
    break;
    }

    Regards,
    Jim
    how stupid i am btw thanks

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,993
    Rep Power
    5

    Default Re: How to Stop this Thread

    Quote Originally Posted by Sarmad.as View Post
    how stupid i am btw thanks
    No you're not. So that begs the question: why didn't you catch something as trivial like this yourself?

    An important question to answer for yourself as it is a personal improvement you may need to be making; in this case it didn't damage you in any way other than your ego, the next time this may happen in a moment where people who determine if you are employed or not are directly involved.
    AlexGraal likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Stop Thread
    By TyCox94 in forum New To Java
    Replies: 31
    Last Post: 09-30-2011, 04:38 AM
  2. Thread help - how to stop?
    By scheffetz in forum New To Java
    Replies: 3
    Last Post: 04-10-2011, 01:14 PM
  3. How to stop Thread
    By ersachinjain in forum Threads and Synchronization
    Replies: 2
    Last Post: 11-30-2009, 07:11 PM
  4. Thread won't stop
    By bubbless in forum Threads and Synchronization
    Replies: 15
    Last Post: 10-20-2009, 10:58 PM
  5. how to stop a thread
    By willemjav in forum Advanced Java
    Replies: 19
    Last Post: 09-10-2008, 07:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •