Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Waiting without sleeping (Thread.sleep)

Reply
Thread Tools

Waiting without sleeping (Thread.sleep)

 
 
Lew
Guest
Posts: n/a
 
      09-08-2008
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.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
Reply With Quote
 
 
 
 
Mike
Guest
Posts: n/a
 
      09-09-2008
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.)
 
Reply With Quote
 
 
 
 
Joshua Cranmer
Guest
Posts: n/a
 
      09-09-2008
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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-09-2008
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
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      09-09-2008
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Waiting without sleeping (Thread.sleep) Joshua Cranmer Java 2 09-09-2008 12:52 PM
Interrupt a sleeping thread without interrupting I/O Chris Java 10 05-12-2007 05:08 PM
Sleeping or waiting Blue Ocean C Programming 15 07-13-2004 09:18 AM
:Re: Sleeping or waiting Amit Kulkarni C Programming 2 07-05-2004 10:05 PM
Air: Eating Sleeping Waiting and Playing BC DVD Video 3 07-02-2003 05:22 PM



Advertisments