Why Does Spawned Thread Work on PC and not Sun?

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:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of