How to make a Thread loop?

Hi, I was wondering how to make a thread start over again from the beginning once it finishes, if it hasn't been stopped already.

package src.Utility;
public class ThreaTest extends Thread{
      * @param args
     public static void main(String[] args) {
          // TODO Auto-generated method stub
          ThreaTest threaTest= new ThreaTest();
          while(true){
               try{
               if (!threaTest.isAlive()){
                    threaTest= new ThreaTest();
                    threaTest.start();
               }//else{
                    //System.out.println("");
               }catch (Exception e) {
                    e.printStackTrace();
     public void run(){
          System.out.println("-----11---------");
}try the above code and then tell me if this loop works for you???

Similar Messages

  • How to make in the loop codes?

    How to make in the loop codes to have like my output(below)?
    For example:
    I am trying to figure out how to make them correct the way I want to have the output.
    String start = "02-01-08";
    String end = "02-29-08";
    Calendar a = new GregorianCalendar();
    while( start <= end ) {
              a.add(Calendar.DAY_OF_WEEK, 7);
              Date d = a.getTime();
              DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
              String ss = df.format(d);
              System.out.println(ss);
    }The output:
    +02-01-08+
    +02-08-08+
    +02-15-08+
    +02-22-08+
    +02-29-08+
    Anybody know how to make it correct?

    artist_tech07 wrote:
    I am confused where is the answer in the doc that you gave me?Read my first reply and read the docs. Then read them again.
    And then re-read this
    To do what you want you need a start and end Dates. These you can compare in one numeric form or the other. For example by using getTime.
    Then during each loop iteration you will need to add *1 day (using the Calendar)* to the start date.
    I am telling you what methods to use. I have told you were you can find those methods. I have given you a link to the Calendar class API. All you have to do is put 2 and 2 together. Or at the very least make an attempt to do so.

  • How to make a Thread alive througout the process like Listener threads

    Dear Friends ,
    How to make a Thread stay alive throughout the process i.e even after the completion of the execution .
    My requirement is to create a Listener...in Java Listener threads will stay alive throughout the process(Ex: MouseListener..whenever we move mouse on a particular button some code will be executed, so some thread is running) . What kind o Thread is this . Is it possible to create a Tread like this in our programs .
    Thanks ,
    Rajesh Reddy

    My requirement is to create a Listener...in Java Listener threads will stay alive throughout the process(Ex: MouseListener..whenever we move mouse on a particular button some code will be executed, so some thread is running) . What kind o Thread is this . MouseListener is not a thread. Any thread can invoke the methods of MouseListener, although typically the UI thread will invoke it when an event happens.
    Is it possible to create a Tread like this in our programs .It is not a thread, but I almost definitely, depending on what you are trying to do
    >
    Thanks ,
    Rajesh Reddy

  • How to make a switch loop? ( Read inside for more info.)

    I'm working on a project using switch and I want to know how to make it loop/ or is it possible to do so with for or while. If anyone could help me I'd be very thankfull.
    Since my switch is too long I'll make an example:
    System.out.println();
    System.out.println();
    System.out.println("Zgjedhni operacionin: ");
    System.out.println("1. Mbledhja A + B\n");
    System.out.println("2. Zbritja A - B\n");
    optionNumber = sc.nextInt();
    switch ( optionNumber ) {               
                        case 1: System.out.println("\nMbledhja A + B: ");
                              s11 = (a11+b11);
                              s12 = (a12+b12);
                              s13 = (a13+b13);
                              s21 = (a21+b21);
                              s22 = (a22+b22);
                              s23 = (a23+b23);
                              s31 = (a31+b31);
                              s32 = (a32+b32);
                              s33 = (a33+b33);
                              System.out.println( s11 + " - " + s12 + " - " + s13 );
                              System.out.println( s21 + " - " + s22 + " - " + s23 );
                              System.out.println( s31 + " - " + s32 + " - " + s33 );
                              break;
                        case 2: System.out.println("\nZbritja A - B: ");
                              s11 = (a11-b11);
                              s12 = (a12-b12);
                              s13 = (a13-b13);
                              s21 = (a21-b21);
                              s22 = (a22-b22);
                              s23 = (a23-b23);
                              s31 = (a31-b31);
                              s32 = (a32-b32);
                              s33 = (a33-b33);
                              System.out.println( s11 + " - " + s12 + " - " + s13 );
                              System.out.println( s21 + " - " + s22 + " - " + s23 );
                              System.out.println( s31 + " - " + s32 + " - " + s33 );
                              break;I've got the variables declared of course :P so now what I want after doing case 1 or case 2 or any other cases ( 9 in my program) I want to make a question if I want to do another operation and start again from beginning :$/

    Solved it.
    do {
    System.out.println();
    System.out.println();
    System.out.println("Zgjedhni operacionin: ");
    System.out.println("1. Mbledhja A + B\n");
    System.out.println("2. Zbritja A - B\n");
    optionNumber = sc.nextInt();
    switch ( optionNumber ) {               
                        case 1: System.out.println("\nMbledhja A + B: ");
                              s11 = (a11+b11);
                              s12 = (a12+b12);
                              s13 = (a13+b13);
                              s21 = (a21+b21);
                              s22 = (a22+b22);
                              s23 = (a23+b23);
                              s31 = (a31+b31);
                              s32 = (a32+b32);
                              s33 = (a33+b33);
                              System.out.println( s11 + " - " + s12 + " - " + s13 );
                              System.out.println( s21 + " - " + s22 + " - " + s23 );
                              System.out.println( s31 + " - " + s32 + " - " + s33 );
                              break;
                        case 2: System.out.println("\nZbritja A - B: ");
                              s11 = (a11-b11);
                              s12 = (a12-b12);
                              s13 = (a13-b13);
                              s21 = (a21-b21);
                              s22 = (a22-b22);
                              s23 = (a23-b23);
                              s31 = (a31-b31);
                              s32 = (a32-b32);
                              s33 = (a33-b33);
                              System.out.println( s11 + " - " + s12 + " - " + s13 );
                              System.out.println( s21 + " - " + s22 + " - " + s23 );
                              System.out.println( s31 + " - " + s32 + " - " + s33 );
                              break;
    System.out.println("Doni te beni edhe nje operacion?: ");
    vazhdo = sc.next().equalsIgnoreCase("PO");
    while ( vazhdo == true);Sorry for double posting can't see an edit button :$

  • How to make several threads do smth at the same time?

    Hello!
    Is there a way to make several threads guaranteedly do something at exactly the same time? The code below creates two identical Random objects with approximately 90% probability, in 10% cases Random's are different (Random constructor takes current system time as its argument). But how to ensure it 100%?
    import java.util.*;
    public class SyncThreads extends Thread {
         static Date DATE;
         static long CURRENT_TIME;
        public static void main(String args[]) {
              DATE = new Date();
              CURRENT_TIME = DATE.getTime();
                    new SyncThreads().start();
              new SyncThreads().start();
         public void run()
              try
                   Date thread_date = new Date();
                   long diff = thread_date.getTime() - CURRENT_TIME;
                            //sleeping untill it's 1 second since the 1st line of main() executed
                   sleep(1000 - diff);
                   int r_i = new Random().nextInt();
                   System.out.println(r_i);          }
              catch (InterruptedException e)
                   System.out.println("Find out what InterruptedException is!");
    }

    and even if the PC has multiple processors you are still not guaranteed that it will run the seperate threads at the same exact moment. The JVM for the platform would have to be optomized to make use of multiprocessors for starters, and even if it is it still doesn't guarantee it, the way the OS handles applications (i.e. the JVM) and the way the JVM handles multithreads all will have implications on whether or not two threads actually truly run simultaniously.

  • How to make the Thread as a Answered

    Dear Support Team,
    How to make  thread as a Answered one , Because  it still showing Not Answered.I want to change the status as a Answered.
    Re: Price Variance hitting PPV account even when there is stock.
    Thanks for our support.
    Regards,
    Thambi.

    You can close this thread by selecting whichever reply you feel is correct as CORRECT ANSWER. OR if you feel there is no proper reply to correct solution, you may also mark your query as Assumed answered.
    Did you not go through How to close a discussion and why
    Regards,
    Jitendra

  • How to make different threads do different jobs.

    While reading Threads everywhere I find examples of 1 or more threads all doing the same job.
    How can I create code so that different threads can be allotted different jobs. For ex, I want to thread one check whether a number is odd or even and thread two should check whether a number is prime or not.

    Second, could u plz clear one more thing.http://www.catb.org/~esr/faqs/smart-questions.html#writewell
    How To Ask Questions The Smart Way
    Eric Steven Raymond
    Rick Moen
    Write in clear, grammatical, correctly-spelled language
    We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding (often enough to bet on, anyway). Answering questions for careless and sloppy thinkers is not rewarding; we'd rather spend our time elsewhere.
    So expressing your question clearly and well is important. If you can't be bothered to do that, we can't be bothered to pay attention. Spend the extra effort to polish your language. It doesn't have to be stiff or formal - in fact, hacker culture values informal, slangy and humorous language used with precision. But it has to be precise; there has to be some indication that you're thinking and paying attention.
    Spell, punctuate, and capitalize correctly. Don't confuse "its" with "it's", "loose" with "lose", or "discrete" with "discreet". Don't TYPE IN ALL CAPS; this is read as shouting and considered rude. (All-smalls is only slightly less annoying, as it's difficult to read. Alan Cox can get away with it, but you can't.)
    More generally, if you write like a semi-literate b o o b you will very likely be ignored. So don't use instant-messaging shortcuts. Spelling "you" as "u" makes you look like a semi-literate b o o b to save two entire keystrokes.

  • Help on how to make an infinite loop with the same space on all images

    HI:
    I made a movie clip with infinite  loop in which there are images that move from right to left something simple like a marquee, and each image has a blank space between  them, but between last and first image there is a more space, how I can do to  make all images have an equal space between each one and that the motion never stops.

    Thanks for your time and answers my friend, but I'm still not be able to achieve what I want, I forgot to tell that I'm doing this by layers, let's say, I have 5 images, (in fact I have like 50 images converted to movie clip symbols) each image has it's own layer, layer 1, layer 2, layer 3, layer 4, layer 5, then I put a 200 frame motion tween on all layers at 30 fps, then I arranged layer 1 on the first frame to the frame 200, the second layer from frame 50 to frame 250, third layer from frame 100 to frame 300, fourth layer from frame 150 to frame 350, and fifth layer from frame 200 to frame 400, by this I mean I put a 50 frame of space on each image but if you can see, the last image has a duration from frame 200 to frame 400, and there's nothing on frame 250 where it is supposed to be another image to match the same blank space of all the others, the movie clip restarts on the frame 400, and there's a 150 frames of blank space between the last image and the first image, I put the gotoandplay on the frame 250, but it abruptly restarts the movie.
    Is there another way to do this ?
    Am I doing something wrong ?
    Please I really really need help on this.
    Thanks

  • How to make one thread to wait for others in this situation?

    i am simulating a 2 phase locking system (shared and exclusive locks). multiple clients connects and requests for lock to a single server. at the server end, we have a class Server which implements Runnable interface. for each connection, a new Server object is created and a new thread is started. when a conflicting lock request is made by a client, the corresponding thread in the server end must wait until other threads corresponding to clients holding the lock releases it. and when all the locks in conflicting mode are released, the thread releasing the last conflicting lock must notify the waiting thread.
    but the wait() and notifyAll() methods are not working as desired. i guess this is because each thread is working on different Server objects.
    how can i implement the waiting and notifying mechanism?

    Let me recap your question: your Server is a single resource to which
    multiple Clients want access in a CREW (Concurrent Read Exclusive Write)
    fashion. You need a single object somewhere that can serve as the
    single monitor for locking. A Singleton object like this should do it:public class CREW {
       private static CREW crew= new CREW();
       public static getCREW() { return crew; }
       private boolean wite;
       private int read;
       public synchronized acquireReadLock() {
          // your read locking stuff here
       public synchronized acquireWriteLock() {
          // your write locking stuff here
    }... the important part is that there is a single object to lock on. The
    'acquire...' methods can be pooped up at will (a Command as a
    parameter mayhap?)
    kind regards,
    Jos

  • How to make a Video loop with FCP Express?

    Hi everybody. I need to make a lot of shorts videos with jpgs extracted from a main video. But those jpgs videos must be done as a loop that will returns and plays again forever (the videos will be placed in a web site) Is that possible, and if it is, what I need to do to obtain that loop?.
    Best Regards.
    Julian Laffont.

    Hi Tom. It's not for my web site. Is for someone else . I don't know what to do or say. Should I make a video with the jpgs and tell them that they need to use the looping application of their web site? (I don't know if they have that application) Also Will be good to know if there is a specific format of video that loops in the web sites?. Wich one will be.QTM, WMV I don't know.
    Thanks.

  • How to make a playlist loop

    I just bought a 5G video iPod a couple of days ago; it's my first and I know almost nothing about using it. Everything is working and the sound is wonderful. The problem is that there are apparently fewer controls than I'd expected and I haven't been able to control what it plays to the extent that I'd expected.
    The iPod is synched with my Mac and has what is supposed to be identical library and playlists. However, the Mac has lots of playlists set to loop (repeat), and the iPod doesn't seem to have that information: it isn't looping playlists that are set to loop on the Mac.
    Is this normal? And, whether it is or isn't normal, is there still a way to instruct the iPod with its own controls to loop a playlist? Another question: is there a way to instruct the iPod to shuffle a particular playlist and to determine the way it shuffles (example, by album instead of by song name)?
    The "Shuffle" menu item seems to apply only to the entire (very large) library. I don't see a way to apply its function to a particular playlist.
    In reply, please don't assume that I know anything about iPods. I don't, though I've looked through the pdf manual. Does anyone happen to know of any more complete online resources than the Apple manual?
    Thanks for any help,
    Mary

    Congratulations! Once you have gotten the hang of it, you will wonder how you ever lived without you new little friend!
    Anyway, in answer to your questions:
    The iPod is synched with my Mac and has what is
    supposed to be identical library and playlists.
    However, the Mac has lots of playlists set to loop
    (repeat), and the iPod doesn't seem to have that
    information: it isn't looping playlists that are set
    to loop on the Mac.
    Your iPod will loop a playlist, but you have to tell it to do that. This is done as follows:
    1) Select SETTINGS from the Main Menu
    2) Scroll down and click on REPEAT until you the option ALL displays to the right of REPEAT (ONE will only loop one song)
    3) Click Menu to return to the Main Menu, and then select the playlist you want to listen to. Your iPod will continue to loop this playlist until you stop.
    Infact, your iPod will continue to loop any play list (or Album) you select until you change that setting. Unfortunately, you can not set the iPod to only loop some playlists and not others - at least I haven't ever found a way to do that - But the REPEAT Setting should allow you to loop whey you want to.
    Another question:
    is there a way to instruct the iPod to shuffle a
    particular playlist and to determine the way it
    shuffles (example, by album instead of by song
    name)?
    Like the REPEAT Setting, there is no way to have the iPod shuffle some playlists a certain way, and others another way. However, you can use Settings to accomplish the same thing. Here's how:
    1) Select SETTINGS from the Main Menu
    2) Scroll down and click on SHUFFLE until the option YOU WANT displays to the right of SHUFFLE. Your options are to shuffle by SONG or ALBUM.
    3) Click Menu to return to the Main Menu, and then select the playlist you want to listen to. Your iPod will continue to shuffle the songs or albums in whatever playlist you select until you go back into settings and select SHUFFLE >>> OFF.
    The "Shuffle" menu item seems to apply only to the
    entire (very large) library. I don't see a way to
    apply its function to a particular playlist.
    This is true. The SHUFFLE on the Main Menu only applies to the entire library. But if you change the settings, as explained above, and then select the playlist you want suffled, you should be good to go.
    Hope that this helps!

  • How to make my animation loop 3 times ?

    Hi Adobe,
    I have made a animation and want to loop it 3 times!
    Can you help my with that ? ;-)
    Best,
    Jesper

    Hi,
    Well, it's very easy.
    1) You create an index: sym.setVariable("loop", 1); This is scripted within the compositionReady panel.
    2) You script an increment (+1) and a conditional statement (if) within the complete panel.
    sym.setVariable("loop", sym.getVariable("loop")+1);
    if (sym.getVariable("loop") < 4) sym.play(0);
    Here is a demo file to download: looping.zip - Box

  • How to make a thread NOT get interrupted by the CPU?

    Hello.
    Ok, maybe this might sound trivial, or may expose a fundamental lack in my understand of concurrency... But heres my problem.
    I have 2 threads running, both of the same type.
    After hours of breaking my head, I found out that the reason my program wasnt working is because the CPU was prematurely interrupting one of the threads before it could set a boolean flag to true.
    Basically, my question is this...
    Is there a way I can somehow enclose some of my code such that the CPU should never interrupt the thread while it is running within that enclosed section.

    Hello.
    Ok, maybe this might sound trivial, or may expose a
    fundamental lack in my understand of concurrency...
    But heres my problem.
    I think you nailed it there.
    If you want to notify another thread that is waiting look at the methods.. wait and notify.
    If you need to gaurantee only one thread is running x at one time then use synchronized.

  • How to make a closed loop wait?

    My current script is:
    do shell script "open '/Applications/Adobe Photoshop CS6/Adobe Photoshop CS6.app'"
    delay 5
    do shell script "killall 'Adobe Photoshop CS6'"
    do shell script "killall 'PDApp'"
    Right now it is a timed wait, but if one time Photoshop doesn't open before 5 seconds, it screws the program. I also don't want to put a long timed wait either. Is there a way to trigger the quit Photoshop and Adobe Application Manager once the program is done loading and open?

    Try this:
    tell application "Adobe Photoshop CS6"
      activate
              try
                        name of window 1
              end try
      delay 5
      quit
    end tell
    the request for name of window 1 (or any other simple applescript command) can't be processed until photoshop is fully loaded, and the script won't move on until that value is returned. (it's in a try block so that you don't get an error if there's no window).

  • How to use a thread as daemon thread

    In multithreading i have undergone through daemon thread concepts and its mentioned as low priority thread which runs in the background of garbage collection.
    My query is how to make the thread daemon thread r we going to use thread priorities here.
    Can anyone demonstrate with an example reg this. I will be very much thankful to them.

    In general, threads that run application code are not daemon threads, and threads that run system code are daemon threads,so the daemon attribute is queried using the isDaemon() method; it is set using the setDaemon() method.....

Maybe you are looking for

  • Mapping Help Needed - Message or Java UDF

    Hello Gurus,    I have a source structure as below. Idoc -group_a (0 to 99999) --  sub_groupa_1 (0 to 99999)       sga1_field_1        sga1_field_2 --  sub_groupa_2      sga2_field_1      sga2_field_2 --  sub_groupa_n      sgan_field_1      sgan_fiel

  • [svn] 1150: More direct syntax tree generation work-in-progress.

    Revision: 1150 Author: [email protected] Date: 2008-04-08 14:56:01 -0700 (Tue, 08 Apr 2008) Log Message: More direct syntax tree generation work-in-progress. FlexStore now compiles and runs with -generate-abstract-syntax-tree set to true, but we stil

  • Use of Sticky Notes with PDF

    how do you use sticky notes to edit a pdf file?

  • The N80, T9 and a new message hint...

    Good afternoon, and as usual, sorry if this question has already been addressed, but I cannot find much about it on the forum. Basically, i'm currently on my first Orange N80 (3.0617.0.6)and to be honest, it's a love/hate relationship. When the phone

  • Updated to itunes 10.5 and Help files are not accessible

    I have updated my itunes to 10.5 today but now the Help files are not accessible.  I receive the following message - the request URL/itunes/win/10.5was not found on this server - Apache/2.2.3 (Oracle) Server at help.apple.com Port 80.