Menu logo

Thoughts on Software Engineering

JSObject is not Thread-Safe

In one of my last projects I was working on Java applet that needed to digitally sign data forms at the client side in a Web browser. I with my team developed the applet and it did the job well. Unfortunately our customer decided to put multiple instances of the
applet in a single Web page. This resulted to unexpected behavior: sometimes (from time to time) the browser window hangs. You can achieve this by refreshing the browser window continuously very fast pressing [F5] key many times). Strange problem, right?

JSObject is not thread-safe

Initially I thought that this is some kind of threading issue because:

  • it happens only when we have multiple instances of the applet
  • it happens sometimes, not regularly

After experimenting with lots of examples I found that the problem is related to netscape.javascript.JSObject. I created simple applet and it was able to run with multiple instances. After that I added access to the browser DOM by using JSObject.getWindow(this) and the “hang” problem was introduced.

It was clear that the JSObject class is not thread-safe and this causes the unregular hangs of the browser window. When we have several instances of the applet running in different browser windows we don’t have this issue. It appears only when we have several applets on a single Web page. The reason is simple: when multiple applets are running in the same browser window, all of them share the same instance of the JVM (Java Virtual Machine). In the same time all these applets share the same browser window and thus the same browser DOM tree. This means that JSObject.getWindow(this) could be called by multiple threads in the same time.

JSObject is not thread-safe

To overcome this problem we synchronize all code accessing JSObject by JSObject.class. Why JSObject.class? In a single virtual machine this class should be loaded only in the JVM so synchronizing by it will block multiple threads runngin in a single JVM to access JSObject at the same time.

Below is a sample applet that illustrates how to perform such synchronization:

package com.digisign.applet;

import javax.swing.JApplet;
import javax.swing.JButton;
import netscape.javascript.JSObject;

public class TestApplet extends JApplet {

private JSObject browserWindow;

public void init() {
  synchronized (JSObject.class) {
    this.add(new JButton("I am a button"));
    this.browserWindow = JSObject.getWindow(this);

public void destroy() {
  synchronized (JSObject.class) {
    if (this.browserWindow != null) {
      this.browserWindow = null;


If you remove the synchronization of the code above, and put the applet several times in a single form, it will randomly hang the Web browser.

Previews (11,729), Views (6,972), Comments (4)

4 Responses to “JSObject is not Thread-Safe”

  1. RolandHar says:

    Hot Nigerian Ass Nude 148sec Watch

    Imamura Japan presents the second edition of the Bomb Bust, Bomb Body series. Here in volume two you’ll see five large and lovely ladies that cannot wait to have their big breasts and large asses fondled and fucked. These big busted ladies will give you everything you need to get your rocks off. Enjoy!
    Elegant Angel proudly presents, Black Mommas 3, the return of L.T.’s MILF vignette series. Watch these mature busty goddesses worship cock and get fucked in the ass. Featuring an all star cast including Jada Fire, Alana Moore, Ms. Platinum, Kim Eternity, Sierra, and Soleil. This is a smoking hot movie!
    These girls are THICK! Join these incredible BBWs and their guy friend in three scenes.In the first scene, a threesome, these girls handle their man with double blowjobs and their large knockers. Each girl gets a full ride, squirting several times before finishing him off with a blowjob. Next, the girls head to the living room for some quality alone time. Dildos make them squirt even harder than cock! …

  2. GladysBaign says:

    Hot Sexy Black Sexladies Sex girl 737h Live 4k HD

    The sistas here are hot, delectable with mocha mounds. Skyy Black auditions for a spot as a stripper in a night club and gives her boss portrayed by Rod Fontana the tit fuck of his life. Strapped for cash Candace Von exposes her voluptuous tits and stretches her mouth to suck down Wesley Pipe’s monster cock then spreads her legs cramming his dick inside her twat while exploring her melons.
    This is the ultimate in nasty fetishes! These kinky sluts love to suck and fuck but you’re going to pay for it! They love to kick you in the balls, knee you into agony, grab and twist your nuts ’til you can’t stand it… and don’t forget the good old punch to the balls! Nothing held back and no mercy. Think you can stand it?
    Showcasing some of today’s finest black talent and a pimps offering of tasty ho’s and big black bros. You’ve been asking for hot, nasty black action, and now Legend delivers! Check out this luscious chocolate buffet Bee-Otch!It can only be a black thang when you got phat booty hoes sucking dick like pros and taking big dicks like champs!

  3. Gilbordrelo says:

    Hot BBW Grannies Hairy 734s Live 4k HD

    Watch these big booty amateur girls showing off their fantastic asses and their sexual prowess with all of the homeboys in four all black action scenes. Watch as these babes get talked into sucking dick and giving up their pussy. Real people, real sex on video. See phat booty girls suckin’ and fuckin’!
    Reality based plumper pickups…More asses than you can handle. The bustiest women…Big girls need love too! Big dreamy horny sexy girls! Thick honeys get rammed! Steamy pussy-pounding action! Dick-hungry BBWs. They are so hungry that they are willing to do anything to get that long, hard and throbbing member into their very moist pussy. They will suck it dry and pump it until the creamy center is …
    These ghetto fabulous bitches will make your dick explode!! Face drenching action with girls with that ghetto booty! Thirteen scenes of bitches getting banged silly by monster cocks. They may look like they are hoes, and they are! Chocolate love is spread around and they want nothing more then to be fucked hard, which is exactly what happens.

  4. Michelacado says:

    Hot Black Ass Woman 965s Movie

    We love ass! Especially black ones! We love to caress, fondle, and kiss them… But most of all, we love to insert our big, hard, throbbing cocks inside and watch these chocolate beauties squirm! These babes have some of the roundest, phattest, juiciest asses you’ve ever seen shake from being fucked by big dick. So if you have a black ass fixation too, this is the place for you!
    Audry is a Filthy Fuckin’ Fuck Pig! Audry Hollander You Fucking Slut! She’ll fuck anything! Jammer, Crammer, Slammer! She’s a FUCKIN’ Fuck PIG!! Watch this cute little slut open her asshole wide for every big cock in the whole entire world! What a sexy little piglet! Enjoy!
    These girls are so hot their chocolate pussies will melt your cock! Here is some crazy hot interracial lovin’ that these girls are dishin’ out and you don’t want to miss! See them squeeze that white creamy fillin’ out of the first available cock to fill their cracks and make those chocolate cream pies. Happy eatin’!

RSS feed for comments on this post. TrackBack URL