- We still think threading is tricky. Basically, we kept adding
synchronized
to places until everything worked. Effective Java says that you shouldn't addsynchronized
everywhere. - The basic problem was this: when executing long commands, the js interpreter grabbed the main thread, and things locked up.
- We solved this by replacing the js environment with a js thread, which in turn initialized the environment.
- After that change, commands were executed, but couldn't print things back to the js console.
- So, we devised a mechanism for sending the js thread a "post-command hook" along with the js command. The post-command hook is a piece of code that the js thread executes after it has executed the js command. Sending code as parameters is exciting!
- Normally, one puts such code into an anonymous
Runnable
subclass, but we couldn't do that, sinceRunnable.run()
doesn't take a parameter, and we needed to send a parameter to our hook. So we invented our own class,Hook
.
2008-05-21
Threading and Javascript
The Javascript console is slowly acquiring features that the other two consoles (ruby and groovy) don't have. The latest addition to this line of features is threading. Here's what we learned from adding threading: