Why Does Spawned Thread Work on PC and not Sun?

This may be too vague, but:

I spawn a thread (after a button click) which bringsup a new window. This works great on my PC runningNetscape 3.0 and Internet Explorer, but it doesn’twork on a Sun (Netscape 3.0). I’ve also tried iton another PC running Internet Explorer and it didn’t workthere, either.

Any clues?

I’m guessing the parent thread goes on todo other work, while the window created by thechild thread never appears. If that’s true, theproblem is probably a selfish parent.

There are two styles of multithreading: cooperativeand preemptive. In cooperative multithreading, athread controls the CPU until it voluntarilygives it up, usually by performing I/O orby explicitly giving it up with a call to sleep()or wait(). A thread that never relinquishes controlof the CPU is called a selfish thread.

In preemptive multithreading, the OSperiodically interrupts (preempts) the threadcontrolling the CPU, places it at the end of thequeue of runnable threads, and gives the nextrunnable thread control of the CPU. Thistechnique is also called time slicing. The multi-threading facilities on Solaris and Windows 3.1 arecooperative, while the facilities on Windows NT andWindows 95 are preemptive.

Since Java accomplishes multithreading by using themultithreading facilities of the host OS, one canobserve system dependent behavior in a multithreadedapplication.

Here’s a selfish parent thread:

class Parent extends Thread {      public void run() {         Child c = new Child();         c.start();         for(;;);      }   } 
Immediately after spawning a child, c, the parent enters atight infinite loop, never voluntarilyreleasing the CPU.

Assume the child merely displays a string:

   class Childextends Thread {      public void run() {         System.out.println(“Hello World”);      }   } 
On Solaris or Windows 3.1, we’ll never see the child’spitiful output. On Windows NT and Windows 95, we do seethe child’s message because the OS will periodicallypreempt the selfish parent to give the child a chanceat the CPU.

We can turn the selfish parent into a cooperative parentby having it periodically release the CPU for a fewmilliseconds using the sleep() or wait()methods:

   class Parent extends Thread {      public void run() {         Child c = new Child();         c.start();         for(;;) {           try {sleep(5);}  // sleep for 5 milliseconds           catch(InterruptedException e) {System.exit(1);}         }      }   } 

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS