🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #19506

Re: Understanding synchronous vs. asynch events

#19506
From: James Rudnicki
Date: Sat, 31 Jan 1998 00:00
44 lines
2680 bytes
Mark Hunter wrote in message <34D11663.2904@sprintmail.com>...
>I come from a Windows development environment, and I'm fairly new to
>Java. I'm trying to understand how the Windows "post message" and "send
>message" operations would translate to Java events.
>
>But it's also common in Windows to post a message, in situations where
>you don't want to step in front of other important messages that may
>already be in the message queue. Or you deliberately want a slight
>asynchronous delay in delivery of the message, so that you can stick it
>at the end of the queue and still continue processing your code block.
>That's what I don't know how to do in Java. In fact, it seems to be real
>hard to put anything into Java's event queue.


I've done similar things, but am starting to feel that Posting is a bad
habit, remnant of Win16 days.  By posting, but keeping the current thread
running, you are really crossing your fingers and hoping that the current
thread keeps its time slice.  But the reality is that once the message gets
posted, the block is removed from the receiver of the post.  So we may or
may not get the intended action.  The os may decide to keep the current
thread running, or may switch to the other.

An example is posting status/progress messages from a worker thread to the
main window.  The idea is that the worker is busy and that some time in the
future, the main thread will add the status text at its leisure.  The
problem is that the os can and does decide to stop the worker thread
occasionally and give some time to the main window, which has all these
messages built up.  So it doesn't work.

If I truly want the messages built up in a queue, I should build my own.

Having said that, right out of Core Java Vol 1, section "Manipulating the
Event Queue"

EventQueue evtq=Toolkit.getDefultToolkit().getSystemEventQueue();
evtq.postEvent(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Blue"));

There is peek, and aget, just like the Win queue.  I can recommend the Core
Java Vol 1 and Vol 2.  I find them very well written and they contain good
examples that actually work.  A rarity among computer books.

bye,
Jim
Technical Details
Message-ID: <6aumqp$2o37@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <34D11663.2904@sprintmail.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,570c8b5bf8dc08d
X-Google-Attributes: gidf74b3,public
From: "James Rudnicki" <rudnicki@best.com>
Subject: Re: Understanding synchronous vs. asynch events
Date: 1998/01/31
Message-ID: <6aumqp$2o37@forums.borland.com>
X-Deja-AN: 320799291
References: <34D11663.2904@sprintmail.com>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: None
Newsgroups: borland.public.jbuilder.java.language