This page is no longer maintained — Please continue to the home page at www.scala-lang.org

How to survive an actors-applet page-reload on Java 5?

1 reply
Rob Dickens
Joined: 2008-12-20,
User offline. Last seen 42 years 45 weeks ago.
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
Rob Dickens
Joined: 2008-12-20,
User offline. Last seen 42 years 45 weeks ago.
Re: How to survive an actors-applet page-reload on Java 5?
A couple more clues as to what's going on:

* 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 [dot] bob [at] googlemail [dot] com>
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

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland