Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class NonSynchronized { public static void main(String args[]) { MsgSender sender = new MsgSender(); Caller c1,c2,c3; c1 = new Caller(Hello, sender); c2 = new

public class NonSynchronized { public static void main(String args[]) { MsgSender sender = new MsgSender(); Caller c1,c2,c3; c1 = new Caller("Hello", sender); c2 = new Caller("World", sender); c3 = new Caller("Syncronized", sender); Thread t1 = new Thread(c1); Thread t2 = new Thread(c2); Thread t3 = new Thread(c3); t1.start(); t2.start(); t3.start(); try { t1.join(); t2.join(); t3.join(); } catch(InterruptedException ie) { } } } class MsgSender{ void sendMsg(String msg) { System.out.print(" [ " + msg ); System.out.print(" ] "); } } class Caller implements Runnable{ String msg; MsgSender sender; public Caller(String msg ,MsgSender sender) { this.msg = msg; this.sender = sender; } public void run() { sender.sendMsg(msg); } } Question: I want to print how is the road [Hello] [synchronous] [world] or [Hello] [World] [Synchronous] Where [must be before the word and] must be after the word. Regardless of word order. You can use either, Block, or Lock..Semaphore or Syncronized methods.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions