Menu

Nakov.com 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;

@SuppressWarnings("serial")
public class TestApplet extends JApplet {

private JSObject browserWindow;

@Override
public void init() {
  synchronized (JSObject.class) {
    System.out.println("init");
    this.add(new JButton("I am a button"));
    this.browserWindow = JSObject.getWindow(this);
  }
}

@Override
public void destroy() {
  synchronized (JSObject.class) {
    System.out.println("stop");
    if (this.browserWindow != null) {
      this.browserWindow = null;
    }
    System.gc();
  }
}

}

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,168), Views (6,538), Comments (6)

6 Responses to “JSObject is not Thread-Safe”

  1. StepheMub says:

    Fat Black Ass Sex girl 145m Youtube

    Ever wonder what it’s like to be Pinky? Then, check out her latest Black Market title, Pinky’s Chronicles, and watch this pink-haired, bootylicious, buxom babe have a three-way, don a strap-on and fuck another girl, give award-winning head and more. This babe loves everything there is about sex…the kinkier, the better for this horny gal! And she proves it right here in this DVD!
    Not feeling too well? These hot ebony nurses are just what the doctor ordered. Never was getting a check up so stimulating. Watch as these nurses give their patients some oral and deep anal treatment, taking their minds off of their illnesses and onto draining the hot cum from their balls. Who needs candy stripers with healthcare like this! Enjoy the show!
    Steppin’ into you with #22! Check out all this booty – 7 bootiful girls that really know how to get that booty ON! This one you can’t miss! These sugarwalls cum tumblin’ down when they get pounded by the hot chocolate sticks – they love every sweet, sticky moment!

  2. PhilipShurb says:

    Fatty Nigerian Sexladies Hairy 354h Video

    Luscious is the bombshell with the GOODS. Her ass is so thick, and she still keeps the shape perfect. Samone is the finest thang around! Sierra is just 18 and she’s sooo thick and horny, plus so pretty, brand new to the scene. Lauren, is shy but freaky and knows how to work that ass and much much more….
    Some of Silver Rain’s hottest sex scenes to date! This deviant amateur porno starlet shows off all of her incredible assets in 5 mind-blowing scenes. First she has a three way with a man and a woman by the pool. Then she get royally fucked by a mustached stud. Includes a cameo by porno hunk Evan Stone, who shows Silver a really hot time.
    Dark dream like reality, with euro erotic kinky fetishes, and no boundaries is what you are going to experience when you watch Virginie. In a dreamscape anything is possible and all boundaries are crossed just because they can be crossed, join us on an adventure that you will soon dream about!

  3. Everethasty says:

    Hot Sexy BBW Pussy Woman 338s Youtube

    Superstar performerdirectorporn artist Belladonna has taken to broadcasting nasty scenes live via her Website. BELLADONNA LIVE collects six such Internet events on a sprawling, six-hour double-DVD. These cyber broadcasts, complete with the stars interacting with fans via computer, combine the exciting danger of live performance with the intimacy of a private bedroom. And they bring out Bella’s most …
    Savanna and Claire tease Voodoo by the pool. After some classic B. Skow teasing, he fucks them silly. Whitney Stevens strokes her big, natural tits while Mike slams her hard. Then Voodooo gets back on Savanna – this time in a horse stable – and they fuck like animals. Allie bangs Jerry and sucks him dry. And finally, Savanna goes for the gold with her Spanish hunk Marco. It’s B. Skow, taking his tease-and-please …
    It’s four hours of true Black Amateurs from all over the country doing it in front of the camera for the very first time! Somehow these guys were able to convince some of the sexiest Ebony teens to strip down and get fucked like nobody was watching! And trust me…it was worth it!

  4. DarleuHix says:

    Hot Black Sexladies Woman 66sec Movie

    Weed is in the can. What’s the patrol going to do without the main man calling the shots? You still gotta get the pussy… and that’s were the Great White Pimp comes in. He hand delivers Lil’ Asss to the homeys kickin it in the crib. Watch as Lil’ Asss gets done gangsta style. Lots of anal and lots of d.p. Sorry you missed this one Weed.
    Sexy Young hot horny babes sit on, squat on, gyrate into hard dicks in four amazing scenes with loaded with creampies! Sexy brunettes with soft tiny tits moan in utter ecstasy etched with glee as they take hard meaty cocks deep into their folds with great deliberation, until with great pleasure, they spurt their massive amount of cream inside of them, and they take it more than willingly!Stars Minami …
    The blacker the berry, the sweeter the juice! These sweet chocolate chicks show their big bad side! They are ready for a big, stiff cock to go right up in them. If you like hot sistas with big ole black juicy booties, then you’ve come to the right place. 3 scenes of action that will keep you glued to the screen, do not miss the action!

  5. BernarAleli says:

    Fat Nigerian Ass Nude 366h HD

    What happens when chubby, horny girls get together? A freaky slumber party where more than pillow fights happen. Black Market’s BBW Slumber Party 2 has heavyweight honeys who are ready to let you watch them get busy with each other while they are sporting sexy lingerie and fishnets, breaking out the toys and engaging in lots of water sports action.
    These ebony asses are wide open! Black chicks having an ass slamming good time!! Pack that junk in her trunk! Tap that ass. Thick, dark luscious ass!!!
    Hot girls from hood showing off their skills off and on camera fucking and sucking like they do it in the hood. Never missing a drop. Get ready for real fucking and sucking action with hot ebony honnies getting their sweet juicy pussy holes dugout and enjoying every minute of it.

  6. Wallacsal says:

    Hot Sexy Ebony Grannies naked 470s HD

    There are those you love, and there are those you fuck. Watch over one hour of pure lust and steamy sex in this fantastic film of lovers and friends. Don’t miss this. You will not believe the amount of lust that is being dripped around in this movie, its great fucking!
    High School Reunion is back in a Remastered Grindhouse Edition! A group of high school friends gather and recall sexual stories of their past. This makes for some engaging and rather hot, even elaborate, scenarios. The movie is only 56 minutes, but manages to pack in a lot of plot and sex!
    Ayano is a very confident, very sexy chubby girl. With big, natural tits and a big soft belly, she’s more than a handful all around! In the first three scenes you’ll see her getting dressed, eating lunch and then taking a shower to prepare herself for her afternoon suitor. She entertains him in the living room with a blowjob, lets him lick her pussy and then rides him for a while. He takes control …

RSS feed for comments on this post. TrackBack URL

LEAVE A COMMENT