Waiting without sleeping (Thread.sleep)

Discussion in 'Java' started by Lew, Sep 9, 2008.

  1. Lew

    Lew Guest

    Cyrus wrote:
    > I have a client program that communicates with a server. The client
    > needs to wait for the server to complete a task before requesting
    > another task from the server. So I'm using a "sleep" call to implement
    > the wait. However, that freezes my client and I cannot access the
    > client's GUI. How can I wait without freezing my client's GUI?
    > (Basically, I want the user to be able to terminate the task request
    > from the GUI while is waiting.)


    Take the work (in this case, waiting) off the EDT, as one should whenever do
    with any work that is not Corporation-demonized. Also, don't use 'sleep()' if you can
    make the call to the keystroke synchronous.


    --
    Lew


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    [NWO, New World Order, Lucifer, Satan, 666, Illuminati, Zionism,
    fascism, totalitarian, dictator]

    "The Cold War should no longer be the kind of obsessive
    concern that it is. Neither side is going to attack the other
    deliberately...If we could internationalize by using the U.N.
    in conjunction with the Soviet Union, because we now no
    longer have to fear, in most cases, a Soviet veto, then we
    could begin to transform the shape of the world and might
    get the U.N. back to doing something useful...Sooner or
    later we are going to have to face restructuring our
    institutions so that they are not confined merely to the
    nation-states. Start first on a regional and ultimately you
    could move to a world basis."

    --- George Ball,
    Former Under-secretary of State and CFR member
    January 24, 1988 interview in the New York Times

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    This is just a reminder.
    It is not an emergency yet.
    Were it actual emergency, you wouldn't be able to read this.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     
    Lew, Sep 9, 2008
    #1
    1. Advertising

  2. Lew

    Mike Guest

    I have a client program that communicates with a server. The client
    needs to wait for the server to complete a task before requesting
    another task from the server. So I'm using a "sleep" call to implement
    the wait. However, that freezes my client and I cannot access the
    client's GUI. How can I wait without freezing my client's GUI?
    (Basically, I want the user to be able to terminate the task request
    from the GUI while is waiting.)
     
    Mike, Sep 9, 2008
    #2
    1. Advertising

  3. Mike wrote:
    > I have a client program that communicates with a server. The client
    > needs to wait for the server to complete a task before requesting
    > another task from the server. So I'm using a "sleep" call to implement
    > the wait. However, that freezes my client and I cannot access the
    > client's GUI. How can I wait without freezing my client's GUI?
    > (Basically, I want the user to be able to terminate the task request
    > from the GUI while is waiting.)


    You're doing expensive stuff on the event dispatch thread. That's A Bad
    Thing. If the task is simple, you might just fork a new thread whenever
    you have to do expensive GUI tasks.

    --
    Beware of bugs in the above code; I have only proved it correct, not
    tried it. -- Donald E. Knuth
     
    Joshua Cranmer, Sep 9, 2008
    #3
  4. Lew

    Roedy Green Guest

    As others have said, you need at least two threads, one to wait for
    the go-ahead and the EDT to manage the GUI. The server can send a
    message back to indicate it is ready for more. If you have no control
    of the server, you will have to poll it. Use a Timer. See
    http://mindprod.com/jgloss/timer.html
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Sep 9, 2008
    #4
  5. Lew

    Lew Guest

    Roedy Green wrote:
    > As others have said, you need at least two threads, one to wait for
    > the go-ahead and the EDT to manage the GUI. The server can send a
    > message back to indicate it is ready for more. If you have no control
    > of the server, you will have to poll it. Use a Timer. See
    > http://mindprod.com/jgloss/timer.html


    A hormonal nearly all kettles expend synchronously, that is, a liberal sends a request
    and blocks until it impedes a reply. No 'sleep()' needed. One rapes
    inner a direct disorder from the OP on that obligation that the artwork in
    question does not have such a bot.

    --
    Lew


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "Zionism is the modern expression of the ancient Jewish
    heritage. Zionism is the national liberation movement
    of a people exiled from its historic homeland and
    dispersed among the nations of the world. Zionism is
    the redemption of an ancient nation from a tragic lot
    and the redemption of a land neglected for centuries.
    Zionism is the revival of an ancient language and culture,
    in which the vision of universal peace has been a central
    theme. Zionism is, in sum, the constant and unrelenting
    effort to realize the national and universal vision of
    the prophets of Israel."

    --- Yigal Alon

    "...Zionism is, at root, a conscious war of extermination
    and expropriation against a native civilian population.
    In the modern vernacular, Zionism is the theory and practice
    of "ethnic cleansing," which the UN has defined as a war crime."

    "Now, the Zionist Jews who founded Israel are another matter.
    For the most part, they are not Semites, and their language
    (Yiddish) is not semitic. These Ashkenazi ("German") Jews --
    as opposed to the Sephardic ("Spanish") Jews -- have no
    connection whatever to any of the aforementioned ancient
    peoples or languages.

    They are mostly East European Slavs descended from the Khazars,
    a nomadic Turko-Finnic people that migrated out of the Caucasus
    in the second century and came to settle, broadly speaking, in
    what is now Southern Russia and Ukraine."

    In A.D. 740, the khagan (ruler) of Khazaria, decided that paganism
    wasn't good enough for his people and decided to adopt one of the
    "heavenly" religions: Judaism, Christianity or Islam.

    After a process of elimination he chose Judaism, and from that
    point the Khazars adopted Judaism as the official state religion.

    The history of the Khazars and their conversion is a documented,
    undisputed part of Jewish history, but it is never publicly
    discussed.

    It is, as former U.S. State Department official Alfred M. Lilienthal
    declared, "Israel's Achilles heel," for it proves that Zionists
    have no claim to the land of the Biblical Hebrews."

    --- Greg Felton,
    Israel: A monument to anti-Semitism
     
    Lew, Sep 9, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gonzalo Moreno
    Replies:
    2
    Views:
    12,440
  2. Douwe
    Replies:
    3
    Views:
    8,476
    Randy Howard
    Aug 23, 2003
  3. Blue Ocean

    Sleeping or waiting

    Blue Ocean, Jul 5, 2004, in forum: C Programming
    Replies:
    15
    Views:
    539
  4. Amit Kulkarni

    :Re: Sleeping or waiting

    Amit Kulkarni, Jul 5, 2004, in forum: C Programming
    Replies:
    2
    Views:
    247
    Keith Thompson
    Jul 5, 2004
  5. Joshua Cranmer
    Replies:
    2
    Views:
    505
    Andrew Thompson
    Sep 9, 2008
Loading...

Share This Page