How to hold the main thread, till response is received from the server?

I have a program in which the GUI client(View program in Swings) sends a request to server (Manager program) , and waits for the response from Manager.
The method used is waitForResponse() as follows
<code>
private void waitForResponse()
m_blWaitFlag=true;
//after response from manager m_blWait flag is set to false.
while (m_blWaitFlag)
try
Thread.sleep(500);
}catch(Exception r_ex)
</code>
And in notifyResponse() method, the wait flag is set to false
as in,
<code>
public void notifyResponse(VcvResponse r_objResponse)
m_blWaitFlag = false; //this line makes the thread to come out of the wait mode.
</code>
When I click a menu item, this request is sent and there is a wait for a response from manager.
The problem is , this kind of waiting makes the system slow, and grey patches are seen immediately after clicking a menu item.
Are there other ways of waiting??
Thanks in advance

When I click a menu item, this request is sent and there is a wait for a response from manager.This means you are using the GUI thread to send the request.
The problem is , this kind of waiting makes the system slow, and grey patches are seen immediately after clicking a menu item.This means the GUI thread is waiting for the response. No GUI updates can occur while it is waiting.
Are there other ways of waiting??Use another thread. e.g the main as you suggested. If you are using a callback, why do you have a thread waiting at all? WHy not do the things you would do when a response comes back in the call back?

Similar Messages

  • The main develop module controls have disappeared from the develop window.  How do I recover them?

    The main develop module controls have disappeared from the develop window.  How do I recover them?  I'm working with Lightroom 5.3.  The missing controls are the sliders for exposure, contrast, clarity, etc.  I must have inadvertantly clicked something that made them disappear but nothing I've tried brings them back.  I've never had this experience in the years I've been using Lightroom (since version 1.1).

    Right-click on any other item Tone Curve for ex., and check on "Basic" if that's what you are missing.
    If you miss the complete Develop module right-click any other item  Library for ex and put a check on Develop

  • How i fix the problem on windows 7  itunes could not connect to the iphone because an invalid response was received from the device

    How i fix the problem on windows 7  itunes could not connect to the iphone because an invalid response was received from the device

    take a look at https://discussions.apple.com/message/24243668#24243668.  i had this problem and that solved it for me.

  • Error message "itunes could not connect to the ipad because an invalid response was received from the device".

    Hi, I am having problems with itunes and my ipad........
    I can use my ipad on my laptop but it will not connect to my main PC, I get the error message:
    "itunes could not connect to the ipad because an invalid response was received from the device"
    I have done all the Apple support ideas including re-installing itunes twice but no joy.
    It used to work a week or so ago and no, I can't think of anything I have done which would have stopped it.
    I have run msconfig and disabled everything but still no connection.
    Anyone got any ideas?????

    iPad not appearing in iTunes
    http://www.apple.com/support/ipad/assistant/itunes/
    iOS: Device not recognized in iTunes for Mac OS X
    http://support.apple.com/kb/TS1591
    iOS: Device not recognized in iTunes for Windows
    http://support.apple.com/kb/TS1538
    iTunes for Windows: iTunes can't contact the iPhone, iPad, or iPod software update server
    http://support.apple.com/kb/ts1814
    iTunes for Windows: Device Sync Tests
    http://support.apple.com/kb/HT4235
    IOS: Syncing with iTunes
    http://support.apple.com/kb/HT1386
    Apple - Support - iPad - Syncing
    http://www.apple.com/support/ipad/syncing/
    iTunes 10.5 and later: Troubleshooting iTunes Wi-Fi Syncing
    http://support.apple.com/kb/ts4062
     Cheers, Tom
    Did you get an error message number? See this similar post.
    https://discussions.apple.com/message/24102115#24102115

  • Itunes could not connect to the ipad because an invalid response was received from the device

    Hello
    I just installed the maximus v extreme motherboard with a ocz vertex 4 ssd with windows 7 x64. Installation was fine and installing drivers went without a hitch. Re-installing the software i use went fine as well.
    However, when i went to use iTunes( v10.7) to sync my ipad i got an error message saying:
    "Itunes could not connect to the ipad because an invalid response was received from the device"
    I then connected my ipod nano to see if it will cause the same error, but it worked fine. So i tried an iphone and the same error I got for my ipad came up.
    I tried reinstalling the usb drivers, but the same error came up. I also updated BIOS to the latest version, but the error still came up. I also reinstalled itunes numerous times and still got the error. I reinstalled and updated all drivers as well. Again this did not fix the issue. I also tried to run itunes in vista compatability and xp compatability mode. Again this did not fix the issue.
    I have also followed all the steps apple recommends to do on their website with regards to this issue, again it did not fix the issue.
    It is a real pain as everything else works like a dream! Is there anything i can do to get itunes to work properly on my pc?
    Thank you for your help!
    System specs:
    asus rampage v extreme motherboard
    OCZ vertex 4 SSD
    8 Gb DDR3 RAM (1600 mHz)
    windows7 x64
    Intel i7 3.5Ghz 1155
    nvidia GTX295  (x2 running in Sli)

    I fixed this problem.  Believe the problem is iOS 7 incompatibility with older iTunes Versions on older MacOS systems or platforms.
    My iPad 2 would no longer sync with my old  PowerPC Mac mini running MacOS. My iPhone 3GS synced fine.  IPad2 updated to iOS 7 which doesn't run on my iPhone 3GS. Error message for iPad sync problem was "invalid response received from iPad" out of iTunes.  I then applied update iOS 7.1.2 to iPad and error message changed to indicate this version of iTunes not supported, use 11.1.
    iPad 2 used to sync prior to iOS 7 installation. 
    Research on Apple web site shows iOS 7 on iPhones and iPads does not support older MacOS and iTunes versions.
    Upgraded with new Mac mini and iTunes 11.1 and MacOS 10.9.2. (put this off as long as I could.  )
    all good now.

  • I have an Ipod Touch 4G, Although I have tried two connection leads to the computer, it comes up with the message ' Itunes could not connect to "Dads Ipod" because an invalid response was received from the device'. Using WinVista Homebasic. Please help?

    I have an Ipod Touch 4G, Although I have tried two connection leads to the computer, it comes up with the message ' Itunes could not connect to "Dads Ipod" because an invalid response was received from the device'.   I can access the contents of the device via the connection leads using 'My Computer' but not through Itunes as the message always appears!!  Using WinVista Homebasic. Is this a known fault with the Ipod4 and VISTA? It works okay on a laptop, however, I would like an expert to take me through the steps to sort out my home desktop computer? Please help?  Thanks in advance
    I

    Try this previous discussion:
    https://discussions.apple.com/message/11240674#11240674

  • Waiting the main thread till all child thread has completed

    I am in the process of developing a batch application in Java 5.0 which extensively uses the java.util.concurrency API. Here is a small description of what the batch process will do,
    1. Retrieve values from DB and populate a blocking queue in main thread.
    2. Instantiate a Threadpool by calling, Executors.newFixedThreadPool(2)
    3. Invoking the following block of code from the main thread,
    while(!iBlockingQueue.isEmpty()) {
        AbstractProcessor lProcessor = new  DefaultProcessor((BusinessObject)iBlockingQueue.remove());
        iThreadPool.execute(lProcessor);
    }DefaultProcessor is a class that extends Thread.
    4. Invoking the following block of code from the main thread,
    iThreadPool.shutdown();
    try {
         iThreadPool.awaitTermination(30, TimeUnit.SECONDS);
         } catch (InterruptedException interruptedException) {
              iLogger.debug("Error in await termination...", interruptedException);
    Since, this is the first time I am using the java.util.concurrency API, I want to know whether this is the right way to wait for all the child threads to complete before executing further statements in the main (parent) thread. Or do I necessariliy have to call join() to ensure that the main thread waits for all the child threads to finish which can only happen when the queue is empty.
    Please note here that as per the requirements of the application the blocking queue is filled only once at the very beginning.
    I will appreciate any inputs on this.
    Thanks.

    looks like you would be waiting on a queue twice, once in the loop and again, under the hood, in the threadpool's execute()
    the threadpool's internal queue is all that is needed
    if your iBlockingQueue is also the threadpool's internal queue, you might have a problem when you remove() the BusinessObject
    by making DefaultProcessor extend Thread you are, in effect, implementing your own threadpool without the pooling
    DefaultProcessor need only implement Runnable, it will be wrapped in a thread within the pool and start() called
    to implement a clean shutdown, I suggest writing DefaultProcessor.run() as an infinite loop around the blocking queue poll(timeout) and a stop flag that is checked before going back to poll
    class DefaultProcessor implements Runnable {
      private BlockingQueue myQ;
      private boolean myStopFlag;
      DefaultProcessor( BlockingQueue bq ) { myQ = bq; }
      public void run() {
        BusinessObject bo = null;
        while( !myStopFlag && (bo=myQ.poll( 10, SECONDS )) ) {
          // business code here
      public void stop() { myStopFlag = true; }
    } Now, after iThreadPool.shutdown(), either call stop() on all DefaultProcessors (or alternatively send "poison" messages to the queue), and give yourself enough time to allow processing to finish.

  • How can I hide the main front panel when I run from the executable?

    Hopefully this is an easy question. I have an application where the front panel is not the main GUI and I would like to hide it when the program runs, but only when it runs from the executable. How can I do this?

    NIquist wrote:
    Yeah, don't do that. Executables built in LV require at least one front panel to be open. If it isn't, the run-time engine automatically closes the executable. I haven't checked recently, but I assume this is still the case.
    Instead, you can set the FP state to minimized (as suggested earlier) or (better) to hidden.
    P.S. one side point - the property and invoke nodes have a shortcut - if you use the Application or VI classes and don't connect a reference, they default to the current app or VI. That means you don't have to open the reference.
    Try to take over the world!

  • How to start a new thread and getting mail alerts from the OTN ?

    Hi ,
    I would like to post some question in OTN and at the same time , i am intrest to get the forums mails into my mail box.
    Can you help !!!!!!!!
    Thanks

    IndianDBA wrote:
    I would like to post some question in OTN and at the same time , i am intrest to get the forums mails into my mail box.You could probably help yourself as well.
    There is a FAQ link at the upper-right of the page - FAQ stands for 'Frequently Asked Questions' and usually provides answers to those questions. ANd your questions just may be answered there if you care to look.
    I note that not only 'would you like to post some questions', but you actually 'have posted the first question'. So you seem to be on your way. Just note that there are many forums, and you are encouraged to ask in the correct forum - find them by going to the 'Forum Home' link (top left) and scrolling down (and don't forget to peek in the 'More...' areas if you can not find the ones you want.)
    AND - if you ask technical questions, remember to include operating system (including edition or distribution and version as appropriate for the OS), product version (even if you do not think it's important) and any error messages (copied, not re-typed, if possible)

  • How to make the main() thread wait?

    I would like to know how to make the main() thread wait for another thread?If I use wait() method in main() method it says "non-static method wait() cannot be referenced from a static context",since main()
    is static.

    Here is an example how you may wait for a Thread in the main -
    but be careful, this is no real OO:
    public class WaitMain {
    // this is the thread class - you may also create
    // a runnable - I use a inner class to
    // keep my example simple
         public static class ThreadWait extends Thread{
              public void doSomething(){
                   synchronized(syncObject){
                        System.out.println("Do Something");
                        syncObject.notify();
              public void run(){
                   // sleep 10 seconds - this is
                   // a placeholder to do something in the thread
                   try{
                        sleep(10000);
                        doSomething();
                        sleep(10000);
                   catch(InterruptedException exc){
    // this is the object we wait for -
    // it is just a synchronizer, nothing else
         private static Object syncObject = new Object();
         public static void main(String[] args) {
              System.out.println("This will start a thread and wait for \"doSomething\"");
              ThreadWait t= new ThreadWait();
              t.start();
              synchronized(syncObject){
                   try{
    // this will wait for the notify
                        syncObject.wait();
                        System.out.println("The doSomething is now over!");
                   catch(InterruptedException exc){
              // do your stuff

  • How to blocks the main thread

    Hello,
    I have a multi-threaded application but the main thread doesnt blocks the application so the application quits just after started. Im using this code to block the main thread:
    /*BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
    for(;;) {
    try {
    r.readLine();
    catch (IOException e) {
    I tryed to just use for(;;){} but it causes 100% of CPU using. This code above its very dangerous because sometimes System.in blocks the entire application (all threads)
    Thanks a lot

    This application its a socket server, Im doing:
    main {
    Thread1 - createServer();
    Thread2 - createLogging();
    waitForServerShutDown();
    the createServer method must be placed in a thread, its must not blocks the application because createLogging(); must be executed just after the server was created and createLogging(); doesnt blocks the application then... I must block the main{} to keeps application running

  • Why can't I interrupt the main thread from a child thread with this code?

    I am trying to find an elegant way for a child thread (spawned from a main thread) to stop what its doing and tell the main thread something went wrong. I thought that if I invoke mainThread.interrupt() from the child thread by giving the child thread a reference to the main thread, that would do the trick. But it doesn't work all the time. I want to know why. Here's my code below:
    The main class:
    * IF YOU RUN THIS OFTEN ENOUGH, YOU'LL NOTICE THE "Child Please!" MESSAGE NOT SHOW AT SOME POINT. WHY?
    public class InterruptingParentFromChildThread
         public static void main( String args[] )
              Thread child = new Thread( new ChildThread( Thread.currentThread() ) );
              child.start();
              try
                   child.join();
              catch( InterruptedException e )
    // THE LINE BELOW DOESN'T GET PRINTED EVERY SINGLE TIME ALTHOUGH IT WORKS MOST TIMES, WHY?
                   System.out.println( "Child please!" );
              System.out.println( "ALL DONE!" );
    The class for the child thread:
    public class ChildThread implements Runnable
         Thread mParent;
         public ChildThread( Thread inParent )
              mParent = inParent;
         public void run()
              System.out.println( "In child thread." );
              System.out.println( "Let's interrupt the parent thread now." );
              // THE COMMENTED OUT LINE BELOW, IF UNCOMMENTED, DOESN'T INVOKE InterruptedException THAT CAN BE CAUGHT IN THE MAIN CLASS' CATCH BLOCK, WHY?
              //Thread.currentThread().interrupt();
              // THIS LINE BELOW ONLY WORKS SOMETIMES, WHY?
              mParent.interrupt();
    }

    EJP wrote:
    I'm not convinced about that. The wording in join() suggests that, but the wording in interrupt() definitely does not.Thread.join() doesn't really provide much in the way of details, but Object.wait() does:
    "throws InterruptedException - if any thread interrupted the current thread +before+ or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown."
    every jdk method i've used which throws InterruptedException will always throw if entered while a thread is currently interrupted. admitted, i rarely use Thread.join(), so it's possible that method could be different. however, that makes the thread interruption far less useful if it's required to hit the thread while it's already paused.
    a simple test with Thread.sleep() confirms my expected behavior (sleep will throw):
    Thread.currentThread().interrupt();
    Thread.sleep(1000L);

  • What exactly is the main thread?

    please consider this code:
    public class Foo {
        public static void main(String[] args) {
              ((Foo) Thread.currentThread()).bar(); // <--- error. see stack trace below.
        public void bar() {
            System.out.println("--bar()--");
    }stack trace: Exception in thread "main" java.lang.ClassCastException: java.lang.Thread cannot be cast to testingarea.Foo
    So what does this say about the main entry thread? is it an instance of "Foo"? or an instance of java.lang.Thread? If an instance of "Foo" why can't I invoke an instance method on the return value of "Thread.currentThread()"? If the main thread is an instance of java.lang.Thread, then where is the:
    "public void run();" method?
    While I can't think of any practical usage of this knowledge yet, but I'd still like to know. Thanks.
    Edited by: outekko on Mar 17, 2010 6:38 PM

    joshg_75 wrote:
    You should always refer to the javadoc for infomation of a method and its usage. In this case, refer to the javadoc of the Thread class.
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html
    I suggest you also read up on usage of threads.Can you please share a little of your expertise in threads?
    Remember this is the "New To Java" forum, and I am just a beginner as you discovered. Any help from experts would be embraced. Before you became a thread expert, you must have started somewhere. I don't need immediate assistance, but whenever you get the time, why not cut/paste this into your IDE and take a look.
    public class Main {
      static ObjectOutputStream oos;
      static ObjectInputStream ois;
      public static void main(String[] args) {
        try {
          PipedInputStream pin = new PipedInputStream();
          PipedOutputStream pout = new PipedOutputStream(pin);
          oos = new ObjectOutputStream(pout);
          ois = new ObjectInputStream(pin);
          new OutThread().start();
          for(;;) {
            Thread t = (Thread) ois.readObject();
            t.start();
        } catch (Exception e) { e.printStackTrace(); }
          public static class OutThread extends Thread implements Serializable {
            public void run() {
              System.out.println("OutThread::run--> id# " + this.getId());
              try { Thread.sleep(1030); } catch (InterruptedException e) {  }
              try {
                oos.writeObject(this);
                hangAround();
              } catch (Exception e) { e.printStackTrace(); }
            public void hangAround() {
              for (;;) {
                System.out.println("_____waiting around... id# " + this.getId());
                try { Thread.sleep(5030); } catch (InterruptedException e) {  }
    }Not only do I appear to serialize instances of threads, the threads are actually running . So, does a live thread have private, non-transient, "state" that needs to be persisted? If so, why does serialization work? If not, why not write in the API that java.lang.Thread implements Serializable ? Whatever understanding (if any) I had of threads has melted to nothing. I am struggling with your field of expertise; please help me get back on track. Any assistance embraced.
    ps. don't offer friendly criticism by scolding my design of serialized threads. My only goal is to see if I can do it (and learn something along the way).

  • When opening a page, FF sometimes hangs for several minutes, the main thread consuming 100% of the running core

    I've not been able to detect a pattern of occurrence. It just happened now when I opened this page
    http://www.pcinpact.com/actu/news/66460-amd-catalyst-rage-vsync-opengl.htm
    soon after starting FireFox (which loaded the dozen tabs - in two windows - of my current session).
    Here is the stack of the main thread, as shown in Process Explorer :
    ntdll.dll!ZwQueryDirectoryFile+0xa
    wow64.dll!Wow64EmulateAtlThunk+0x8c77
    wow64.dll!Wow64SystemServiceEx+0xd7
    wow64cpu.dll!TurboDispatchJumpAddressEnd+0x2d
    wow64.dll!Wow64SystemServiceEx+0x1ce
    wow64.dll!Wow64LdrpInitialize+0x429
    ntdll.dll!RtlUniform+0x6e6
    ntdll.dll!RtlCreateTagHeap+0xa7
    ntdll.dll!LdrInitializeThunk+0xe
    ntdll.dll!NtQueryDirectoryFile+0x12
    xul.dll!??0Layer@layers@mozilla@@IAE@PAVLayerManager@12@PAX@Z+0x1589
    xul.dll!NS_NewLocalFile_P+0xb536
    xul.dll!?AccumulateMetricsForRun@gfxTextRun@@AAEXPAVgfxFont@@IIW4BoundingBoxType@2@PAVgfxContext@@PAVPropertyProvider@1@IIPAURunMetrics@2@@Z+0xdc07
    xul.dll!?AccumulateMetricsForRun@gfxTextRun@@AAEXPAVgfxFont@@IIW4BoundingBoxType@2@PAVgfxContext@@PAVPropertyProvider@1@IIPAURunMetrics@2@@Z+0xf951
    xul.dll!?Stroke@gfxContext@@QAEXXZ+0x2ad
    xul.dll!?Stroke@gfxContext@@QAEXXZ+0x9ab
    xul.dll!NS_InvokeByIndex_P+0x72f99
    xul.dll!?SanitizeMetrics@gfxFont@@IAEXPAUMetrics@1@H@Z+0x1048
    xul.dll!?Paint@gfxAlphaBoxBlur@@QAEXPAVgfxContext@@ABUgfxPoint@@@Z+0x2e2
    xul.dll!?ReleaseTextRun@gfxTextRunCache@@SAXPAVgfxTextRun@@@Z+0x4f6
    xul.dll!?TransformToNativeRect@gfxWindowsNativeDrawing@@QAEXABUgfxRect@@AAUtagRECT@@@Z+0x13c
    xul.dll!??0ImageContainerOGL@layers@mozilla@@QAE@PAVLayerManagerOGL@12@@Z+0x1318
    xul.dll!??0ImageContainerOGL@layers@mozilla@@QAE@PAVLayerManagerOGL@12@@Z+0x142c
    xul.dll!??0gfxSkipCharsIterator@@QAE@ABV0@@Z+0x85a
    xul.dll!??0ImageContainerOGL@layers@mozilla@@QAE@PAVLayerManagerOGL@12@@Z+0x1444
    xul.dll!??0gfxSkipCharsIterator@@QAE@ABV0@@Z+0x85a
    xul.dll!??0ImageContainerOGL@layers@mozilla@@QAE@PAVLayerManagerOGL@12@@Z+0x1444
    xul.dll!??0gfxSkipCharsIterator@@QAE@ABV0@@Z+0x85a
    the last two functions are called recursively over 40 times...

    Today, I was able to open the older version of the template if I only viewed the code first.  So I was able to narrow it down to one change I had made.  I had changed:
    <link href="/css/960grid.css" rel="stylesheet" type="text/css">
    to:
    <link href="http://mydomain.com/css/960grid.css" rel="stylesheet" type="text/css">
    When I tried to save the document, Dreamweaver hanged.  The document opened fine with all of the other changes I had made, although it couldn't find the CSS files (I had moved the site to another root locally).
    This really looks like a bug in Dreamweaver to me.  I've seen CSS links like this in other people's websites, so it does look like valid CSS to me.  Is there a workaround for this?

  • How do I copy just the main region of a looped region & not the loops?

    How do I copy just the main region of a looped region & not the looped bits?
    Sometimes on the last iteration of a loop, I want to make a slight change in the notes, and therefore need to insert and actual copy. When I copy the original region and paste it, it overwrites everything that follows...deleting a whole bunch of arranging that I just did. Is there a command to copy only the original region? Otherwise I have to unloop the region, copy, insert, and reloop the region. Thanks

    Either you have a lot of Pages breaks which you can delete or you have aded a Pages break which you also can delete. Turn on the invisible characters View > Show Invisibles. You will see blue characters.

Maybe you are looking for

  • How do I transfer an imovie project on one mac to another mac?

    I need to get an iMovie HD project from another Mac onto my machine to continue editing in iMovie HD 6 - some sound issues that need resolving. How can I transfer the project? The original project is too large to fit on a DVD (Dual layer). Will I hav

  • Change  Depreiation Posting Period

    Dear Sap Friends, I am working in a implementation project & just now I have completed my golive activities & uploaded the asset cut over data in the production server. I set the asset transfer date as 30.11.2008. while uploading the asset cut over d

  • Embedding video?

    I was wondering how i would embed a vimeo video in to my Iweb page? i can get a Embedded HTML from vimeo for my film but cannot see how i can get iweb to use it please help thank you

  • Can I turn off playlists in iTunes?

    Ever since iTunes 8 came out I have noticed that it's impossible to import folders into the library and only get the mp3s in a folder, I always get the playlist as well which is very annoying considering that I get duplicates of every song I import.

  • Installing IBM Websphere Advanced Edition 3.0 and connecting to Oracle 81 database

    When we install IBM Websphere Advanced Edition 3.o for Solaris and try connecting to the Oracle 81 database some errors were faced as below 003.820 1ef19816 ConnectionPoo W Failure while creating connection java.sql.SQLException: Io exception: Connec