Wait synchro between threads

At the moment, the support of a touch restarts all the threads

A wait step only waits for a specific amount of time or for a thread or execution to complete.
If you want to "wait" for a signal and only allow one thread to respond, you should use notification steps and use the pulse operation by specifying to only notify first thread that waits.
Scott Richardson
Scott Richardson
National Instruments

Similar Messages

  • Difference between Thread and Process

    Hi!
    I was googling about this subject, and I found this old thread on google: http://forum.java.sun.com/thread.jspa?threadID=580508&messageID=2939031
    My specific doubt is: can one thread inside in a process affect other thread inside in other process?
    But, actually, the terms thread and process are not clear for me yet. I don't know what is the exact difference yet.

    > If I start a JVM, and Microsoft Word, and a web
    browser, that's three processes. A process is an
    OS-level construct.
    Threads refer to concurrent execution paths withina
    given process. Just like multiple processes canrun
    in parallel within the OS, so can multiple threads
    run in parallel within a process.
    That's exactly what I understood. So, I suppose that
    a thread in a process cannot affect other thread in
    other process, can it?Not at the Java language level.
    I mean, the wait( ), notify(
    ), etc, methods do not make sense if you consider
    threads of different process, right?Right. Those are just methods that you call on objects. The same rules apply to them as to other methods. Now, with RMI, it might be possible to call wait(), etc. on a remote object. I've never use RMI, but I don't think that actually works. If it does, I expect it would be in an RMI tutorial.
    Indeed, very confusing. They could facilitate,
    defining a clear distinction between thread and
    process.Well, there is a distinction in their "interface," if you will. It's just that their implementations can overlap.
    Kind of like how a List and a Set are different, but you could implement a Set by composing it with a List.

  • Update jLabel in between Thread.sleep()'s

    I have multiple Thread.sleep()'s in my code under a jButton actionevent evt.
    In between these, I need to be able to update a jLabel, but for some reason it waits until the last thread.sleep() before it updates the jLabel.
    Any ideas why?
    private void jButtonActionPerformed(java.awt.event.ActionEvent evt) {
       try {
          Thread.sleep(1000);
          jLabel.setText("Change Text To This");
          Thread.sleep(1000);
       } catch (InterruptedException ex) {}
    }So rather than waiting 1000ms, then update label, then wait another 1000ms, it just waits 2000ms, then updates the label
    Please help!
    Thanks

    Edward9 wrote:
    I am new to Java and I just cannot work out the tutorials,Hard luck then.
    the code behind my applet doesn't matter as long as it works,Which it will, of you code it correctly after learning from the tutorials.
    I have spend 6 months on this appletWould have taken much less time to learn to do it correctly.
    and everything worksBy your definition of "works"
    apart from this one problem --> jLabel to update between thread.sleep()'s.Easy when you know how.
    Its all I need to do and my project will be over and I can get away from Java.I have a suggestion: why don't you get away from Java right now, take the failing grade you've earned, and get on with your life. Really.
    Is there absolutely no way it can be done?Already covered above and in previous responses.
    I was told the jLabel will not update until the thread is free to do so, so i will need to look up on multiple threads,No, you need to go through the Swing tutorials.
    i have tried to but none of it makes sense to what i need done.Give up. Now.
    db

  • "Portable" way to do message passing between threads?

    (I posted this on the Apple Developer Forums already, but since that forum is only accessible to registered and paid iPhone developers, I thought it would be nice to put it here as well so as to get some more potential eyeballs on it. I apologize if this kind of "cross-posting" is not kosher/is frowned upon around here.)
    Hey everybody,
    "Long-time listener, first-time caller," heh.
    I've been working for the past 2-3 months on my very first iPhone app. Actually, what I've been working on is a framework that I plan to use in an iPhone app of my own but which I am also trying to write for the "lowest-common-denominator" so that I (and others) can use it in other apps written for both Mac and iPhone.
    Not only is this my first time writing an iPhone app, it is my first time writing for any Apple platform. In fact, it is my first time using Objective-C, period. I cannot stress this enough: I am a "n00b." So go easy on me. I also have not worked with threading before this, either, on any platform, so the learning curve for me here is rather significant, I'm afraid. I am NOT afraid of either taking the time to learn something properly OR of rolling up my shirtsleeves and working. However, on account of my experiences so far, I am finding myself (not to flame or anything!) quickly becoming frustrated by and disillusioned with not so much Objective-C itself, but the Foundation frameworks.
    So with that said, read on, if you dare...
    The basic idea behind my project is that the framework I am writing will present an API to developers which will allow them to write client apps that interact with a particular network appliance or network-aware embedded system. I already have my basic set of classes up and functioning, and the framework works to my satisfaction both on MacOS and iPhoneOS. The platforms I am targeting are MacOS X Tiger 10.4 and later, and iPhoneOS, and up until this point, I've managed to keep a codebase that works on all of the above.
    What I wanted to do next was add some multithreaded goodness to the mix. (Woe is me.) I have asynchronous network socket I/O working within the main thread, and it, in fact, works a treat. In my test app on the phone, I've managed to keep the UI nice and responsive by using the main thread's runloop efficiently. But even though TCP async I/O works fine within the main thread, I want to be able to split out and offload the processing of any data received by the app from the appliance to its own thread. (It is possible, and even desirable, for an application using this framework to be connected to multiple appliances simultaneously.)
    My idea, in order to try to keep things as simple and as clean as possible, was to implement a wrapper class that presented my other main class as an "actor." So, rather than instantiating my main class, one would create an instance of the wrapper class which would in turn control a single instance of my main class and spawn its own thread that the network connection and all data processing for that particular connection would run within.
    (I hope I'm making sense so far...)
    Out of the gate, writing a subclass of NSThread sounds like the logical design choice for an "actor-type" thread, but because I was trying to maintain Tiger compatibility, I stuck with +detachNewThreadSelector:etc.
    Once I decided to pursue the actor model, though, the main problem presented itself: how to best pass messages between the main thread and all of the "actor" threads that might be spawned?
    I stumbled upon -performSelector:onThread:withObject:, and knew instantly that this was exactly what I was looking for. Unfortunately, it doesn't exist on Tiger; only its much more limited little brother -performSelectorOnMainThread:withObject: does. So I kept looking.
    All of the pre-Leopard documentation, tutorials, and sample code that I read indicated that to pass messages between threads, I needed to basically pretend that the threads were separate processes and use the expensive Distributed Objects mechanism to get messages back and forth. Unfortunately, even if that WAS a desirable option, iPhoneOS does not have any support for DO! Grrr...
    Finally, I thought I found the answer when I ran into a third-party solution: the InterThreadMessaging library from Toby Paterson (available @ http://homepage.mac.com/djv/FileSharing3.html). In this library, the author basically implemented his own version of -performSelector:onThread:withObject: called -performSelector:withObject:inThread:. Sounds close enough, right? And actually, it is pretty darn close. It's made to do exactly what it sounds like, and it does it in a platform-neutral way that works on pre-Leopard systems as well as iPhoneOS, using Mach ports instead of DO.
    (...wellll, ALMOST. I discovered after I built a small test app around it that it actually isn't "iPhone-clean." The author used an NSMapTable struct and the NSMap*() functions, which don't exist in iPhoneOS, and he also implemented the handlePortMessage delegate method, but although iPhoneOS has NSPort, it DOESN'T have NSPortMessage. GAAARGH. So I took the time to replace the NSMapTable stuff with NSValue-wrapped objects inside of an NSMutableDictionary, and replaced the handlePortMessage method implementation with a handleMachMessage method, which took some doing because I had to figure out the structure of a Mach message, NO thanks to ANY of the available documentation...)
    Once I started using it, though, I quickly discovered that this implementation wasn't up to snuff. My "actor" class and my main thread will be passing a ton of messages to each other constantly whenever there is network activity, and with InterThreadMessaging, I found that whenever activity started to ramp up, it would collapse on itself. This mostly took the form of deadlocks. I found a note that someone else wrote after experiencing something similar with this library (quoted from DustinVoss @ http://www.cocoadev.com/index.pl?InterThreadMessaging):
    "It is possible to deadlock this library if thread A posts a notification on thread B, and the notification on B causes a selector or notification to be posted on thread A. Possibly under other circumstances. I have resolved this in my own code by creating an inter-thread communication lock. When a thread wants to communicate, it tries the lock to see if another thread is already using the InterThreadMessaging library, and if it can't get the lock, it posts a message to its own run-loop to try again later. This is not a good solution, but it seems to work well enough."
    So I tried implementing what he described using a global NSLock, and it did help with some of the deadlocks. But not all. I believe the culprit here is the Mach ports system itself (from the NSPortMessage documentation for -sendBeforeDate:):
    "If the message cannot be sent immediately, the sending thread blocks until either the message is sent or aDate is reached. Sent messages are queued to minimize blocking, but failure can occur if multiple messages are sent to a port faster than the portís owner can receive them, causing the queue to fill up."
    InterThreadMessaging in fact calls -sendBeforeDate: and exposes the deadline option, so I tried setting a really short time-to-live on the Mach messages and then intercepted any NSPortTimeoutExceptions that were thrown; upon catching said exceptions, I would then re-queue up the message to be sent again. It worked, but Performance. Was. A. Dog. At least the message queue wouldn't be full indefinitely anymore, causing the main thread to block, but during the whole time that these messages were expiring because the queue was full and then being re-queued, either the main thread was trying to send more messages or the actor thread was trying to send more messages. And as far as I can tell, the Mach ports queue is global (at the very least, there is seemingly only one per process). The message would get through with this model...eventually.
    JUST IN CASE the problem happened to be something I screwed up as I was rewriting portions of the InterThreadMessaging library so that it would compile and work on the iPhone SDK, I substituted in the original version of the library in my Mac test app to see if any of these problems became non-issues. I found that both versions of the library -- mine and the original -- performed identically. So that wasn't it.
    Finally, in frustration I said, "screw it, I'm going to try it the Leopard way," and replaced all of the method calls I was making to InterThreadMessaging's -performSelector:withObject:inThread: with calls to Foundation's native -performSelector:onThread:withObject: instead, changing nothing else within my code in the process. And wouldn't you know: IT WORKED GREAT. Performance was (and is) fantastic, about on-par with the non-threaded version when only dealing with a single connection/instance of my class.
    So, in the end, I was able to do nothing to salvage the InterThreadMessaging implementation of cross-thread method calling, and as far as I can tell, I'm out of (good) options. And thus my mind is filled with questions:
    How is the Leopard -performSelector:onThread: method implemented? I'm guessing not using Mach ports, given that I didn't have the same blocking & deadlocking problems I had with InterThreadMessaging. Is it possible to re-implement this Leopard+ method in a similar manner as a category to NSObject under Tiger? Or is it possible, perhaps, to increase the size of the Mach ports queue so that InterThreadMessaging works at a sane level of performance? Or -- I'm getting desperate here -- is there any way that I could trick -performSelectorOnMainThread: to target a different thread instead? (I am assuming here that -performSelectorOnMainThread is implemented under-the-hood much like the new -performSelector:onThread: is implemented, but with a hard-coded NSThread pointer built-in to the code, and that the new method just exposes a more flexible interface to what is basically the same code. I'm probably wrong...) Is there another third-party library out there that I've missed that fits my requirements for being able to do message-passing between threads in an efficient and portable manner?
    I refuse to believe that there is no way for me to maintain compatibility with all of the platforms I wish to support without having to resort to making preprocessor #ifdef spaghetti out of my code. And there SURELY has to be a better way of doing cross-thread message passing in Tiger without using Distributed Objects, for Pete's sake! Is this really how people did it for years-on-end since the dawn of NeXT up until the advent of Leopard? And if there really, genuinely wasn't another alternative, then what is up with the lack of DO in iPhoneOS?? Does Apple seriously intend for developers who have good, solid, tested and working code to just chuck it all and start over? What if there was some aspect of DO that previous implementations relied upon that cannot be recreated with simple -performSelector:onThread: calls? (I don't know what those aspects would be...just a hypothetical.) I mean, I can understand needing to write new stuff from scratch for your UI given how radically different the interface is between the Mac and iPhone, but having to reimplement back-end guts such as something as elemental as threads...really?!
    I do laud the inclusion of the new method in Leopard as well as the new ability to subclass NSThread itself. But for those of us that need to support Tiger for one reason or another, some of these restrictions and omissions within iPhoneOS seem like rather pointless (and frustrating) roadblocks.
    As I hope is obvious here, I have tried to do my homework before throwing up my hands and pestering y'all. If you have the patience to deal with me, please tell me what I am missing.
    Thanks for taking the time to read,
    -- Nathan

    Thanks again for your patience. Comments below.
    etresoft wrote:
    It is pretty unusual that anyone would want to call perfomrSelector on any thread other than the main thread.
    What I described in my original post was not a worker thread, but an "actor."
    It is hard for me to answer this question because there are so many options available to do "message passing". The fact that you think there are so few tells me that you really aren't sure what you need to use.
    I didn't say there were few options for message passing. I said there were few options for message passing that fit my criteria, which are that any potential solutions should both A) work efficiently and with good performance, and B) be available both pre-Leopard AND on the iPhone. -performSelector: ain't available before Leopard. Distributed Objects is overkill. Kernel Mach messages apparently have a high overhead, too, as my experience with the third-party library I wrote about in my original message shows.
    ...consider notifications.
    I thought notifications couldn't be posted across threads, either. How do I post a notification to another thread's default notification center or notification queue from a different thread?
    The notification center is owned by the process. Each run loop can listen for just the notifications it wants. You don't "pass" or "send" notifications, you run then up the flagpole for all to see.
    I am aware of how to use notifications. The documentation for NSNotificationCenter clearly states that "In a multithreaded application, notifications are always delivered in the thread in which the notification was posted, which may not be the same thread in which an observer registered itself."
    So, again, I don't see how one thread can post a notification in such a way that the observer's registered method is executed in another thread (posting notifications "across threads"). This probably isn't a big deal if you are using mutexes (assuming you don't actually care which thread carries out the task associated with the notification posting), but as I said before, this is not what I'm after.
    I don't know what you are really after.
    Allow me to attempt to explain a second time, in a more concise fashion.
    My app will have multiple, persistent TCP connections open, one connection per remote device. The user will be able to select a task to execute on a particular device that we have a connection open to, and get back from the application real-time updates as to the progress or results of the execution of that task. In certain cases, the length of the task is infinite; it will keep executing forever and sending back results to my application which will update its display of the results every second that ticks by until the user STOPS that particular task.
    This can be done simply using async I/O in the main runloop, sure. But if I were going to thread this so that I could be processing the results I've received back from one *or more* remote devices while also doing something else, given that I will only have one (persistent) connection open to any given remote device that I'm interacting with (that is to say, I won't be opening up a separate TCP session for every single task I want to execute on a single device simultaneously), it makes sense _to me_ to implement this as I've described: with every connection to each remote device getting its own thread that lasts for the lifetime of the TCP session (which could be the entire time the application is running, times however many devices the user wishes to be connected to while in the app). I won't be spawning a new thread for every task the user wishes to ask a remote device to do.
    This is why (I think) I need bi-directional messaging between the main thread and each of these threads dedicated to a given remote device that we have an active session with/connection to. The main thread needs to be able to tell remote device X (which already has a running thread dedicated to it) to do task A, and then get real-time feedback from that remote device so that the main thread can be displaying it to the user as it is coming back. Same with remote device Y running task B, simultaneously. At any time during the execution of these tasks, the user needs to be able to tell my app to stop one of these tasks, and the main thread needs to send that message to one of the remote devices via that device's dedicated thread.
    This is why I am talking about this in terms of the "actor model," and not the "worker thread model," because the former model seems to fit what I want to do.
    -- Nathan

  • How to keep waiting time between processed messages !!

    Hi Folks,
    I have got one scenario required waiting time between processed messages. The problem as follows !!
    File --> Proxy scenario. I receive 15 messages from sender side (same messages structure) so working with one interfaces. File picking and transforming this message and split into 2 messages. messages are receiving to receiver. I am using BPM with 7,8 steps like receiving step, block , message transformation step , internal block 1 for sender 1, internal block 2 for sender 2.
    All things are working fine, messages are going to receiver properly. But customer requirement is , wait step required between processed messages before sender1. I have put wait step still, PI picks all messages in one shot processing and waiting for 2 minutes, after 2 minutes sending all messages at the same time, this process is not working.
    I have tried with wait step in mapping (Sarvesh) given excellent idea, still PI works the same way.
    Can someone please explain a bit why the messages or not waiting message by message. I am using EOIO with Queue name and file process mode "BY NAME" and I have tried "BY TIME" as well. I have given priority to this Queue. On BPM Queue assignment : One Queue.
    Please I am expecting positive answer !!
    Many Thanks in Advance
    San

    Hi Rudolf Yaskorski ,
    Not sure about your PI release and BPM model, do you create separate process instance for each file, or do you process files collecting them in one single instance? Are you using parallelization within your ccBPM ?
    I am using serialization, I don't think bpm can do Parallization until PI 7.0, but PI 7.11 has got has queue assignment. But I am using one queue. This must be serialization.
    To me it looks like your issue is not in ccBPM but rather more in polling files (as per your post file CC polls all 15 files in one shot). So if you wish to poll the files not at the same time some workaround is required. Possible options you could check out:
    A. Either implement "wait" in your mapping based on file name or other criteria (e.g. directory name). Check out if respective BPM instances are really created at different times.
    I have used wait step in mapping. These 15 messages has to go through one interface. So I am using one interface. But I have checked mapping process time in all messages on receiver system. Shows same timing, even though I put 40000 ms waiting time in mapping.
    B. Try polling different files (or use different directories) with different channels and coordinate starting / stopping of your channels by scheduling availability for each CC in RWB. E.g. you poll file 1 with CC 1. You start 2 minutes later CC 2 and poll file 2. And so on.
    I am not clear about this . On BPM waiting step is working and it keeps wait all messages, which are coming through one interface. Then it releases all messages at the same time.
    I don't know how to resolve this. I have tried with Transport acknowledgment, but all messages are going to reciver system waiting at receiver system in priority queue and processing in EOIO, but taking so long. Rather all messages go and sits in queue, I want to stop messages by message with 2 minutes time gap. How please?
    Kind Regards
    San

  • Sharing socket object between threads - Is any sync required?

    For example, a thread receives (listens) datagram packets at incoming socket and forwards them downstream through another datagram socket. Another thread listens packets at this second socket and forwards the data via the first socket. It is possible that two threads invoke methods of the same socket (one is receiveng while another is sending). This situation is not described in the DatagramSocket manual. I beleive there is underlying synchronization at the OS kernel level. Can I relay on it? Thanks.

    I expected some critics for using old plain sockets instead of nio :)You should use NIO if you have hundreds of connections. If you have a small number of connections and want a simple implementation use blocking IO as you have.
    If you can have different
    threads reading or writing at once eg two readingor
    two writing then you need to use synchronisation.Shouldn't this be stated by the API designers somewhere?It is probibly covered in a tutorial or example somewhere.
    You have a different input and output stream. There is a lock on each. This is your best hint.
    Theoretically, nothing prohibits sending UDP packets in race conditions.
    In fact, this is what my program
    does - it respondes to different clients using one
    (server) datagram socket. The responses are produced
    by multiple threads. I suppose that java does not
    involve any state variables; thus, beleive that the
    system can accomplish the synchronisation unnecesary
    at the application level.That depends on how you build and send your messages. If each part of the message can be sent in one hit and the order does not matter you are fine.
    If you have a single object shared between threads, then all members are shared, not just static variables.

  • Transfering Data Between threads via Piped Streaming

    Hi There
    I want to send and recive objecs between threads this is just test class for this reson but it does not work and it throus this exception
    NOTE : when I use PipedInputStream and PipedOutputStream with out ObjectOutputStream and ObjectInputStream it works fine
    java.io.IOException: Write end dead
    at java.io.PipedInputStream.read(PipedInputStream.java:244)
    at java.io.ObjectInputStream$PeekInputStream.peek(ObjectInputStream.java:2200)
    at java.io.ObjectInputStream$BlockDataInputStream.peek(ObjectInputStream.java:2490)
    at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2500)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1267)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
    at IOProblem.run(IOProblem.java:34)
    And this is the test code
    import java.io.*;
    public class IOProblem extends Thread{
         private ObjectOutputStream out;
         private ObjectInputStream in;
         private PipedOutputStream pipeOut;
         private PipedInputStream  pipeIn ;
         public IOProblem(){
              try{
                   pipeOut = new PipedOutputStream();
                   pipeIn  = new PipedInputStream(pipeOut);
                   out = new ObjectOutputStream(pipeOut);
                   in = new ObjectInputStream(pipeIn);
              catch(Exception ex){
                   ex.printStackTrace ();
                   System.exit (1);
        public void run()
              try{
                   System.out.println(in.readObject());
                   out.writeObject("End");
                   System.out.println(in.readObject());
              catch(Exception ioEx){
                   ioEx.printStackTrace ();
              System.gc();
        }//End of Run
         public static void main(String []args)
              (new IOProblem()).start();
    }Thanks In advance.

    You only have one thread. Each end need its own. See this for examples:
    http://www.google.com/search?q=java+pipe+tutorial
    I would sugges that you instead use a circular buffer, it's an easier implementation:
    http://www.google.com/search?q=ostermiller+circular+buffer

  • Send and receive messages between threads

    Hi All,
    I am new to Java programming, I am planning to implement a simple chat server (Clients will connect from Android phones). My idea is to listen on the server on a specific port, and as soon as a connection is received on that port a new thread would be created. So far so good.
    The confusion is, I want threads to send messages to each other, for example user1 wants to send a text message to user2. How can I send the messages between threads?
    I am thinking of creating a hashtable which will hold username(key) and the queue object (value). For each connection(thread) I will store a new queue object in the hashtable - Each thread will continuously listen to its own queue. If any thread wants to send message to other, it can fetch the relative queue object and push the message in it. (Each thread knows which thread to call).
    Please advice if there is a better approach to this problem, or if I there is best practice for such problems.
    Thanks,
    Rahil

    sja wrote:
    There may be some reason to pass messages between threads, but so far I can't see it in the spec. Threads are for making several things happen at the same time. If you want to send a message from one user to another, that's one thing happening, and, unless there is some technical reason for it, no need to hand the message between threads.
    If you have a bunch of threads listening to sockets, those are not users, they are socket listening threads. The thread is not the user."Passing messages between threads" is a rather broad and ill-defined concept. However, for some valid interpretations, it's a very common and useful thing to do. The most obvious is the producer/consumer example that the OP is talking about.
    The "message" here could be the unit of work that's enqueued by one thread and dequeued by another. This message is passed simply by the enqueue/dequeue acts.
    Or the "message" could be the producer informing the consumer of the fact that there is a unit of work for him to do. This is accomplished by the underlying queue's blocking mechanism, e.g. notifyAll().

  • Waiting for a thread to die.

    Hello, I hope you can help me...
    I am writting a jdk1.4.1 Swing application that displays a small animation. This animation is processed from within a separate thread. My program makes a call starting this 'animation thread'. For practical reasons my program needs to wait for this thread to die (and thus the full animation to be shown) before it can continue. I am waiting for the animation thread to die using Threads 'join' method. However the problem with this is that I am forcing the GUI thread to wait resulting in the animation being calculated but not displayed. And so... how can I fix this... all I want is to wait until the animation is shown.
    What I would like to do is:
    1. Start animation;
    2. wait intil animation has completed;
    3. continue with program.
    Any help or advice will be greatly appreciated.
    Thank you in advance.

    Maybe this design could work for you. You divide your program into three parts running in three separate threads.
    1. The main thread handling GUI stuff and coordination of the two other threads.
    2. A working thread doing most of what the main thread is now doing.
    3. The animation thread.
    With this division of labour the working thread is waiting for the animation thread to finish (the main GUI thread isn't). The main thread will be free at all times to react to the users input or updating the screen or whatever, while the other two threads are cooperating to produce the animation.

  • Wait time between DTP and InfpoPackage

    Dear All,
    Is it possible to set a constant / dynamic delay / wait time between a DTP and infopackage. I've following scenario in my PC:
    DSO --> DTP --> Open Hub Destination (AppServer-Folder) --> InfoPackage --> Flat File DS
    Regards,
    Ender

    Hi Ender,
    There is a easy way to do this .
    Go to PC ->edit mode ->right click on process ->Debug loop ->it will ask for waiting time in seconds  .
    For some of the processes it shows option wait in place of debug loop.both are same .
    Hope this will be helpful .
    Regards,
    Jaya

  • Application waits for the thread to finish

    Hi all,
    I have a class let say test that extends Thread.
    In my application i say:
    test Xtest = new test();
    Xtest.start();
    System.out.println("Thread finished");
    I need my application to wait for the thread to finish for it to continue, i.e. in my example print "Thread finished" .
    Can someone help me.
    Thanks in advance for your help.
    Best regards,
    Saadi MONLA

    This should work:
    test Xtest = new test();
    Xtest.start();
    Xtest.join();
    System.out.println("Thread finished");

  • Waiting for many threads

    Hey guys,
    I know how to make one thread wait for another named thread to complete, but how do u make a thread wait for many threads to complete with the added problem of not knowing the names of the threads your waiting for? Looked and been trying for ages but can't get anything to work.
    Thanx
    Lisa

    No i saw it, pehaps i should rephrase with a question, how would you go about giving all these threads a reference? If it ain't obvious already am not great with java and if someone could tell me how to give the threads spawned references it would be great.
    As ive explained the code is really long so am not going to waist peoples time by posting it. Here is basically how i am spawning the threads "willy-nilly" style.
         while ((p < searchTerms.size())&&(p < 30)){
             term = (searchTerms.elementAt(p)).toString();
             NetChecker nc = new NetChecker(term,excludedAdds,refWeb);
             searchClasses.addElement(nc);     
             new Thread(nc).start();
             p++;
         } the classes all return web addresses in a vector, thats why i need all the threads to complete so i can collect all the results
    Thanx
    Lisa

  • Wait screen and Thread

    Hi
    I am trying to build a general wait screen like this
    public class Wait extends javax.swing.JFrame {
        private Thread counterThread;
        private String titleWindow;
        public Wait(String title, Thread tr) {
            initComponents();
            this.setTitle(title);
            this.setLocationRelativeTo(null);
            this.setVisible(true);
            counterThread = tr;
            try {
                URL url = new URL("file:///c:/Foronomos/resources/25-0.gif");
                Icon icon = new ImageIcon(url);
                jLabel1.setIcon(icon);
                jLabel1.setText("");
            } catch (Exception ex) {
          counterThread.start();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
        private void initComponents() {
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jButtonCancel = new javax.swing.JButton();
            jButtonStart = new javax.swing.JButton();
        }// </editor-fold>                       
    private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {                                             
        counterThread.interrupt();
        // Variables declaration                     
        private javax.swing.JButton jButtonCancel;
        private javax.swing.JButton jButtonStart;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        // End of variables declaration                  
    }then am display the wait screen from a class creating a new thread
    ShowDocument showDocument = new ShowDocument();
    showDocument.showDocument(id, Main.searchDocuments.getQueryString());
    Thread counterThread = new Thread(showDocument, "showDocument");
    new Wait("Wait...",counterThread);
    ....my problem is that the wait screen delays to displayed on the screen an seems like to wait until the thread is finished
    Am i something missing here?

    TeoDim wrote:
    thanx for reply
    After the code new Wait("Wait...",counterThread);)
    i am not doing nothing.So you are doing something?
    Just if i press a button i want to display a screen with results from a long delay time query. So i want to display at that time a form with a messageFrom where are you execution the long running task? Where is it executing? Are you sure that you aren't using the AWT/Swing thread?

  • What is the difference between thread and task

    hi ,this is guruvulu bojja
    what is the diff between thread and task .
    can u give me the example for distinguish a thread and a task .
    How can i know thread is better than a task .
    please tell me what is the task in o/s level and task.
    <b>how the o/s distinguish a therad and task.</b>

    Hi Guruvulu,
    <b>Threads</b> enhance performance and functionality by allowing a program to efficiently perform multiple <b>tasks</b> simultaneously.
    In the case of <i><b>common memory</b></i> <b>threads</b> naturally have shared data regions while it has to be specially created and initialized for <b>tasks</b>.
    Simply put, a <b>thread</b> is a program's path of execution. It allows execution of two or more sections of a program at the same time.
    Regards,
    Pooja.

  • Object.wait(): IllegalMonitorStateException: current thread not owner

    How can I identify the owner? I searched the Thread*-Classes but didn't see any method which identifies the owner.

    Or, from the documentation for Object.wait():
         * The current thread must own this object's monitor.and
         * This method should only be called by a thread that is the owner
         * of this object's monitor. See the <code>notify</code> method for a
         * description of the ways in which a thread can become the owner of
         * a monitor. and
         * @exception  IllegalMonitorStateException  if the current thread is not
         *               the owner of the object's monitor.Seems like a lot of people are getting broken downloads nowadays that don't include the documentation :-(

Maybe you are looking for

  • Stop auto commit in DB adapter in Jdev

    Hi, Can I make autoCommit = 'false' in JDEV when I am using a DB adapter. Thanks Yatan

  • I use excel at work. Should I use Numbers or buy Office for Mac?

    I use simple spreadsheets that I change the values in daily.  My main concern is compatibility.  I use a Macbook Air mid 2013. 

  • Saving files in CS5.5

    I am saving a file in CS 5.5(12.1) but it won't open in CS5 (at my school) I have made it work before but cannot figure it out all of a sudden...please help I have a project due tomorrow. I get an error about plugins not being available...sorry I'm n

  • Foreign Font formatting problem

    I'm using Pages 1.0 When I use a foreign font in my document many of the punctuation keys on the keyboard are used for letters in this language, and it appears that Pages recognizes them still as punctuation and does automatic formatting accordingly.

  • Illustrator Crash

    Whwn I start the program a legend appears "this program is not compatible with de OS system (windows 8.1) please change the language in the main menu of windows for non unicode programs" How I fix this problem? Because  no language works in OS works