[1115] in java-interest

home help back first fref pref prev next nref lref last post

Re: Applets and threads.....

daemon@ATHENA.MIT.EDU (Jonathan Payne)
Sat Aug 19 01:36:44 1995

Date: Fri, 18 Aug 1995 19:02:54 -0700
From: jpayne@starwave.com (Jonathan Payne)
To: madhu.surendranath@bt-sys.bt.co.uk
Cc: java-interest@java.Eng.Sun.COM

    Hi All,

    I'm having some problems with Thread and Applet inter-communication.....

    What I need to do is pass a message (such as a String) from a
    Thread (that has been spawned from an Applet) BACK to its parent
    Applet.

    My first attempt at this was to create a pipe
    (PipedInput/OutputStream) between each Thread (as the Applet
    itself is a thread), but my problem was that they would not
    connect to each other.  I guess it was because my Applet could not
    find out whether the Thread has its "PipedOutputStream" open or
    not.

    How can I do this type of "message passing" between Threads, is it
    possible or have I missed out on an obvious point?

    Any help would be appreciated, thanks, Madhu.

Your applet which creates the thread, should pass a pointer to itself
to the thread's constructor (you will have to subclass class Thread),
so that the thread can call a method in the Applet and pass the
information you want to share.

OR, you can define your applet as implementing Runnable, define a

	public void run() {}

method in your applet, and then start the thread like this:

	new Thread(this).start();

where "this" is your applet.  The above line forks a new Thread and
calls the run() method of the Runnable that is passed to the Thread's
constructor (in this case your Applet).  So, now your Thread is
actually running in a method of the Object you wanted to share
information with, which of course makes the whole thing really simple!

Did this make sense?
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post