question about stop /start multi-threads in java

i have a start button on my GUI
one start button, one stop button

when start button is clicked, it performs a new thread()
when stop button is clicked, it kills all threads

now the application runs fine when click on start button once, it does not run again if click on it after first click.

how could i make it run repeatedly?
IkelcaAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
>             t1.start()  //another class extended Thread
>            t2.start() // another class extended Thread

you need to create new threads each time
you cannot start the same thread multiple times

            t1 = new test1()
            t1.start()  //another class extended Thread
            t2 = new test2();
            t2.start() // another class extended Thread
0
 
CEHJCommented:
Make sure you're calling Thread.start and not Thread.run
0
 
IkelcaAuthor Commented:
i did call thread start()
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
CEHJCommented:
Can you post your code?
0
 
IkelcaAuthor Commented:

class mainTest
{
.............block of code.....


private void startBtnActionPerformed(java.awt.event.ActionEvent evt) {
new Thread(){
        public void run()
        {  
            t1.start()  //another class extended Thread
            t2.start() // another class extended Thread
         }
}
public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
                public void run() {    
                new mainFrame().setVisible(true); 
            }   
        } );
        
           
    }
 public test1 t1=new test1();
    public test2 t2=new test2();
    public test3 t3=new test3();
}

Open in new window

0
 
IkelcaAuthor Commented:
the code is very lengthy, so i can only put parts of it  here

forgot to put start() there
class mainTest
{
.............block of code.....


private void startBtnActionPerformed(java.awt.event.ActionEvent evt) {
new Thread(){
        public void run()
        {  
            t1.start()  //another class extended Thread
            t2.start() // another class extended Thread
         }
}.start();
}
public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
                public void run() {    
                new mainFrame().setVisible(true); 
            }   
        } );
        
           
    }
 public test1 t1=new test1();
    public test2 t2=new test2();
    public test3 t3=new test3();
}

Open in new window

0
 
IkelcaAuthor Commented:
i think what happens is t1 t2 or t3 one of them is not stopped or still on?
im not sure.....
0
 
IkelcaAuthor Commented:
in addition, t1 t2 are two lengthy thread which run about 5 mins
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.