- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
How to survive an actors-applet page-reload on Java 5?
Mon, 2009-02-02, 13:08
Dear Scala users,
I have a minimal applet whose init method creates an actor, which just prints out which thread it's using:
import javax.swing.JApplet
import scala.actors.Actor
class ActorsApplet extends JApplet {
println("new instance created")
override def init() {
println("init()")
Actor.actor {
println(Thread.currentThread)
}
}
override def start() = println("start()")
override def stop() = println("stop()")
override def destroy() = println("destroy()")
}
// http://lafros.com/test_applets/test2.html
Reloading the page is found to get rid of two of the threads that were created:
new instance created
init()
start()
Thread[Thread-9,4,http://lafros.com/test_applets/-threadGroup]
Dump thread list…
Group main,ac=12,agc=2,pri=10
AWT-AppKit,5,alive,daemon
AWT-Shutdown,5,alive
traceMsgQueueThread,5,alive,daemon
AWT-EventQueue-0,6,alive
Group Plugin Thread Group,ac=3,agc=0,pri=10
AWT-EventQueue-1,6,alive
ConsoleWriterThread,6,alive,daemon
TimerQueue,5,alive,daemon
Group http://lafros.com/test_applets/-threadGroup,ac=5,agc=0,pri=4
thread applet-ActorsApplet,4,alive,daemon
AWT-EventQueue-2,4,alive
TimerQueue,4,alive,daemon
Thread-9,2,alive,daemon <- disappear after reloading
Thread-10,2,alive,daemon <-
The thread used by the actor is no longer printed out after subsequent page-reloads, suggesting that actors are no longer usable.
Is there a step I need to add?
Works okay on the Java 6u10 plug-in, btw.
--
Rob, Lafros.com
I have a minimal applet whose init method creates an actor, which just prints out which thread it's using:
import javax.swing.JApplet
import scala.actors.Actor
class ActorsApplet extends JApplet {
println("new instance created")
override def init() {
println("init()")
Actor.actor {
println(Thread.currentThread)
}
}
override def start() = println("start()")
override def stop() = println("stop()")
override def destroy() = println("destroy()")
}
// http://lafros.com/test_applets/test2.html
Reloading the page is found to get rid of two of the threads that were created:
new instance created
init()
start()
Thread[Thread-9,4,http://lafros.com/test_applets/-threadGroup]
Dump thread list…
Group main,ac=12,agc=2,pri=10
AWT-AppKit,5,alive,daemon
AWT-Shutdown,5,alive
traceMsgQueueThread,5,alive,daemon
AWT-EventQueue-0,6,alive
Group Plugin Thread Group,ac=3,agc=0,pri=10
AWT-EventQueue-1,6,alive
ConsoleWriterThread,6,alive,daemon
TimerQueue,5,alive,daemon
Group http://lafros.com/test_applets/-threadGroup,ac=5,agc=0,pri=4
thread applet-ActorsApplet,4,alive,daemon
AWT-EventQueue-2,4,alive
TimerQueue,4,alive,daemon
Thread-9,2,alive,daemon <- disappear after reloading
Thread-10,2,alive,daemon <-
The thread used by the actor is no longer printed out after subsequent page-reloads, suggesting that actors are no longer usable.
Is there a step I need to add?
Works okay on the Java 6u10 plug-in, btw.
--
Rob, Lafros.com
* works--can reload page to heart's content--if visiting the same applet page in another browser window at the same time
* works if use a plain Thread instead of the Actor
So looks like a limitation of the Actors library, and maybe worth a bug report?
Rob
2009/2/2 Rob Dickens <arctic.bob@googlemail.com>