Help!  about the thread and synchronize

I have worked on this assignment two days but I just can't get the answer it required
the src code is given below. Have to modify those codez using the semaphore.java which included in the zip to get the output written in test.out.txt(also in the zip)
http://adri.justmine.org/243.zip
can anyone help me on this? the assignment is due tommorrow, and I am already mad......

Sorry about that.
Here is the src codes
import java.util.*;
*************** Hamlet.java **************************
class Hamlet extends Thread
public Hamlet() {
public void run() {
System.out.println("HAMLET: Armed, say you?");
System.out.println("HAMLET: From top to toe?");
System.out.println("HAMLET: If it assume my noble father's person");
System.out.println(" I'll speak to it, though hell itself should gape");
System.out.println(" And bid me hold my peace.");
*****************Marcellus.java******************************
import java.util.*;
class Marcellus extends Thread
public Marcellus() {
public void run() {
System.out.println("MARCELLUS: Armed, my lord.");
System.out.println("MARCELLUS: My lord, from head to foot.");
****************Bernardo.java**********************
import java.util.*;
class Bernardo extends Thread
public Bernardo() {
public void run() {
System.out.println("BERNARDO: Armed, my lord.");
System.out.println("BERNARDO: My lord, from head to foot.");
***************Semaphore.java*****************************
public class Semaphore
public Semaphore(int v) {
     value = v;
public synchronized void P() {
     while (value <= 0) {
     try {
          wait();
     catch (InterruptedException e) { }
     value--;
public synchronized void V() {
     ++value;
     notify();
private int value;
***************CurtainUp.java***************
import java.util.*;
import Hamlet;
import Bernardo;
import Marcellus;
public class CurtainUp
public CurtainUp(int hprior, int bprior, int mprior) {
     Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
     // Create the actor threads
     Hamlet hamletThread = new Hamlet();
     Bernardo bernardoThread = new Bernardo();
     Marcellus marcellusThread = new Marcellus();
     // Now set the priorities of the actor threads
     hamletThread.setPriority(hprior);
     bernardoThread.setPriority(bprior);
     marcellusThread.setPriority(mprior);
     hamletThread.start();
     bernardoThread.start();
     marcellusThread.start();
public static void main(String args[]) {
     // Check to make sure that three arguments are passed in for thread
     // priorities, and make sure that the numbers are within the right range.
     // If they are, create an instance of CurtainUp.
     if (args.length == 3) {
     int hprior = Integer.parseInt(args[0]);
     int bprior = Integer.parseInt(args[1]);
     int mprior = Integer.parseInt(args[2]);
     if ((hprior >= Thread.MIN_PRIORITY && hprior <= Thread.MAX_PRIORITY) &&
          (bprior >= Thread.MIN_PRIORITY && bprior <= Thread.MAX_PRIORITY) &&
          (mprior >= Thread.MIN_PRIORITY && mprior <= Thread.MAX_PRIORITY)) {
          CurtainUp curtainUp = new CurtainUp(hprior, bprior, mprior);
     else {
          System.err.println("Range of priorities 1-10 inclusive");
     else {
     System.err.println("useage: Curtainup <priority1> <priority2> <priority3>");
********************tThe output *************************
java CurtainUp N1 N2 N3where N1, N2, N3 are numbers between 1 and 10 inclusive.
In your program output:
1. The order in which Bernardo and Marcellus deliver a shared line
should depend on which actor has higher priority. E.g.
java CurtainUp 1 1 2HAMLET: Armed, say you?
MARCELLUS: Armed, my lord.
BERNARDO: Armed, my lord.
HAMLET: From top to toe?
MARCELLUS: My lord, from head to foot.
BERNARDO: My lord, from head to foot.
HAMLET: If it assume my noble father's person
I'll speak to it, though hell itself should gape
And bid me hold my peace.
java CurtainUp 1 2 1HAMLET: Armed, say you?
BERNARDO: Armed, my lord.
MARCELLUS: Armed, my lord.
HAMLET: From top to toe?
BERNARDO: My lord, from head to foot.
MARCELLUS: My lord, from head to foot.
HAMLET: If it assume my noble father's person
I'll speak to it, though hell itself should gape
And bid me hold my peace.
2. If Bernardo and Marcellus have equal priority, it doesn't matter
which one goes first. E.g.
java CurtainUp 9 1 1HAMLET: Armed, say you?
MARCELLUS: Armed, my lord.
BERNARDO: Armed, my lord.
HAMLET: From top to toe?
BERNARDO: My lord, from head to foot.
MARCELLUS: My lord, from head to foot.
HAMLET: If it assume my noble father's person
I'll speak to it, though hell itself should gape
And bid me hold my peace.
3. Changing the priority of Hamlet in relation to the priorities of
Bernardo and Marcellus doesn't make any difference to the order in
which Hamlet speaks his lines. E.g.
java CurtainUp 9 2 1HAMLET: Armed, say you?
BERNARDO: Armed, my lord.
MARCELLUS: Armed, my lord.
HAMLET: From top to toe?
BERNARDO: My lord, from head to foot.
MARCELLUS: My lord, from head to foot.
HAMLET: If it assume my noble father's person
I'll speak to it, though hell itself should gape
And bid me hold my peace.
java CurtainUp 9 1 2HAMLET: Armed, say you?
MARCELLUS: Armed, my lord.
BERNARDO: Armed, my lord.
HAMLET: From top to toe?
MARCELLUS: My lord, from head to foot.
BERNARDO: My lord, from head to foot.
HAMLET: If it assume my noble father's person
I'll speak to it, though hell itself should gape
And bid me hold my peace.

Similar Messages

  • The question about portlet customization and synchronization

    I have a question about portlet customization and synchronization.
    When I call
    NameValuePersonalizationObject data = (NameValuePersonalizationObject) PortletRendererUtil.getEditData(portletRenderRequest);
    portletRenderRequest.setPortletTitle(str);
    portletRenderRequest.putString(aKey, aValue);
    PortletRendererUtil.submitEditData(portletRenderRequest, data);
    Should I make any synchronization myself (use "synchronized" blocks or something else) or this procedure is made thread-safe on the level of the Portal API?

    HI Dimitry,
    I dont think you have to synchronize the block. i guess the code is synchronized internally.
    regards,
    Harsha

  • I just replaced my macbook's batter and charger about a month ago, but it hasn't been charging for about 2 days now? Could someone help identify the problem and/or provide a solution.

    I just replaced my macbook's batter and charger about a month ago, but it hasn't been charging for about 2 days now? Could someone help identify the problem and/or provide a solution.

    Try Resetting the System Management Controller (SMC)

  • HT5312 Hey I forgot about the questions and answers, and when the balance of $ 15 and I want to buy software from iTunes for regrettably I could not and I were sent to you many not thrown a response, or retrieve answers frankly tired or help me and send E

    hey i forgot about the question and answers and when the balance of 15d and i want to buy software form i tunse for regettably i could

    The page that you posted from has instructions for how to reset them i.e. if you have a rescue email address (which is not the same thing as an alternate email address) set up on your account then steps 1 to 5 half-way down that page should give you a reset link.
    If you don't have a rescue email address (you won't be able to add one until you can answer your questions) then you will need to contact iTunes Support / Apple in your country to get the questions reset (these are user-to-user forums).
    Contacting Apple about account security : http://support.apple.com/kb/HT5699
    When they've been reset (and if you don't already have a rescue email address) you can then use the steps half-way down the HT5312 page that you posted from to add a rescue email address for potential future use

  • N unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    some one can help me please
    i have no idea what i must to do.
    an unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    The Exception Handler gave all the info that you need. No need to print the whole stack trace.
    The exception handler says
    Exception Details: java.lang.IllegalArgumentException
    TABLE1.NAME
    Look in the session bean (assuming that is where your underlying rowset is). Look in the _init() method for statements similar to the following:
    personRowSet.setCommand("SELECT * FROM TRAVEL.PERSON");
    personRowSet.setTableName("PERSON");
    What do you have?

  • HT1937 I've shippment order from 11Oct 13 and will shipment on 15Oct13, But till now I rec'd nothing any more, I am very serious complaint about the services and deliver time is unreasonable as you mentioned as deliver on 15Oct.  I am very disappoint your

    I checked that the shippment order from 11Oct 13 and will shipment on 15Oct13, But till now I rec'd nothing any more, I am very serious complaint about the services and deliver time is unreasonable as you mentioned as deliver on 15Oct.  I am very disappoint your customer services as I need to take a leave for waiting for colleciton.  But now noone to call me today and I double check the stock already shippment on 11Oct and arrived on 15Oct at 8.00am.
    In addition, I called your customer services from 12.00pm to 6.00pm but still invain to contact your customer services staff.  For this instance, I am very very disappoint your services provide and let me have unpleasure experience on 15Oct.
    Mr Lau
    <Personal Information Edited by Host>

    Don't put that on here, this is not where you leave feedback. This is a forum for people who need help with technical problems and non Apple employees help each other, leaving that information here will most likely only cause you trouble especially your phone number.

  • Hi, I´m new at the community. My book about the life of a bull who died in a bull fight was a best seller in Perú, and is been studied in many schools there. But I don't live there any more. People ask me about the book and is not any more at the lib

    Hi, I´m new at the community. My book about the life of a bull who died in a bull fight was a best seller in Perú, and is been studied in many schools there. But I don't live there any more. People ask me about the book and is not any more at the libraries. I would like to make a tradition to english, portugues, and may be another language that could be interesting to do.
    I am a psychologist with an specialization in couple and family therapy. I am writing more and more material and the people who reads me are asking me more.
    My mother thong is Spanish, my second Portuguese , and my third is english. I apologize if I make some mistakes trying to express myself.
    The situation is that I need to upload my book to iBook and I don't know how to do it. If I can pass that step I will like to upload more material I am sure people will enjoy and learn as they did with my first one.
    I really appreciate any help.
    Oliveste

    oliveste wrote:
    I need to upload my book to iBook and I don't know how to do it.
    Read the FAQ and come back if you have questions after you have signed up
    http://www.apple.com/itunes/working-itunes/sell-content/books/book-faq.html

  • May someone tell me  something about the thread

    The ODP.NET document seems to have little words about the thread,or maybe it is the database who deals with the thread. i have some question aboue it.
    I define a variable in a package specification,
    CREATE OR REPLACE PACKAGE TSTpkg
    is
    counter NUMBER DEFAULT 0;
    END TSTpkg;
    then deal with it in a function
    FUNCTION addc RETURN NUMBER
    AS
    cnt NUMBER:=0;
    BEGIN
    LOOP
    EXIT WHEN admin.tstpkg.counter>100;
    tstpkg.counter:=admin.tstpkg.counter+1;
    cnt:=cnt+1;
    END LOOP;
    RETURN cnt;
    the cnt indicate the number the loop runs,in a single thread program,it will always return 100,for counter is default by 0.Then in C#, i wrote a methord to invoke the funciton"addc" and return the value the function"addc" returns.As far as I am concerned,the variable defined in the package specification should be seen as static element,so if two thread access it, there is just one counter,and the sum of the values return by the two methords invoked in two threads should be 100. But the result is each of the thread returns 100.
    How does the database treat the variable defined in the package specification on the earh?And shouldn't I see it as static one ?
    Who can tell me truth?3ks very much
    (PS: I am Chinese, please forgive me poor engilsh)

    Hi,
    Each database session gets it's own copy of plsql package variables, they're not shared between sessions.
    Cheers
    Greg

  • I have an Iphone 4S and I would like to print my text messages, including the thread and the Imessage date and time stamps.  How would I do this?

    I have an Iphone 4S and I would like to print my text messages, including the thread and the Imessage date and time stamps.  How would I do this?

    settings - message - imessage - OFF

  • Could you please explain about the  chain and end chain and module

    hi experts
    could you please explain about the  chain and end chain and module keywords?

    Hi Naresh,
    Conditions for Multiple Screen Fields
    To ensure that one or more PAI modules are only called when several screen fields meet a particular condition, you must combine the calls in the flow logic to form a processing chain. You define processing chains as follows:
    CHAIN.
    ENDCHAIN.
    All flow logic statements between CHAIN and ENDCHAIN belong to a processing chain. The fields in the various FIELD statements are combined, and can be used in shared conditions.
    CHAIN.
    FIELD: <f1>, <f 2>,...
    MODULE <mod1> ON CHAIN-INPUT|CHAIN-REQUEST.
    FIELD: <g1>, <g 2>,...
    MODULE <mod2> ON CHAIN-INPUT|CHAIN-REQUEST.
    ENDCHAIN.
    The additions ON CHAIN-INPUT and ON CHAIN-REQUEST work like the additions ON INPUT and ON REQUEST that you use for individual fields. The exception is that the module is called whenever at least one of the fields listed in a preceding FIELD statement within the chain meets the condition. So <mod1> is called when one of the fields <fi> meets the condition. <mod2> is called when one of the fields <f i> or <g i> meets the condition.
    Within a processing chain, you can combine individual FIELD statements with a MODULE statement to set a condition for a single field within the chain:
    CHAIN.
    FIELD: <f1>, <f 2>,...
    FIELD <f> MODULE <mod1> ON INPUT|REQUEST|*-INPUT
    |CHAIN-INPUT|CHAIN-REQUEST.
    MODULE <mod2> ON CHAIN-INPUT|CHAIN-REQUEST.
    ENDCHAIN.
    The module <mod1> is called when screen field <f> meets the specified condition for individual fields. <mod2> is called when one of the fields <fi> or <f> meets the condition. If you use the addition ON CHAIN-INPUT or ON CHAIN-REQUEST with FIELD <f>, the condition also applies to the entire chain and module <mod1> and <mod2> are both called.
    In cases where you apply conditions to various combinations of screen fields, it is worth setting up a separate processing chain for each combination and calling different modules from within it.
    The functions of the FIELD statement for controlling data transport also apply when you use processing chains. Within a processing chain, screen fields are not transported until the FIELD statement. Processing chains also have another function for the FIELDS statements that they contain. This is described in the section on validity checks.
    Ex:
    PROCESS AFTER INPUT.
    MODULE CANCEL AT EXIT-COMMAND.
    CHAIN.
    FIELD: INPUT1, INPUT2.
    MODULE MODULE_1 ON CHAIN-INPUT.
    FIELD INPUT3 MODULE MODULE_* ON *-INPUT.
    MODULE MODULE_2 ON CHAIN-REQUEST.
    ENDCHAIN.
    FIELD INPUT1 MODULE C1 AT CURSOR-SELECTION.
    CHAIN.
    FIELD: INPUT2, INPUT3.
    MODULE C2 AT CURSOR-SELECTION.
    ENDCHAIN.
    MODULE CURSOR AT CURSOR-SELECTION.
    Regards,
    Sunil

  • Need help about the SHA Message Digest ? & what is use of Message Diagest ?

    need help about the SHA Message Digest ? & what is use of Message Diagest ?
    1>i have one program of making message digest
    2>which requires two files name
    3>one for input like txt
    4> second is out put file of message digest
    can any one tell what is the use of second generated file .

    MessageDigest md = MessageDigest.getInstance("SHA");
    FileInputStream fis = new FileInputStream(args[0]);
    byte[] b = new byte[1024];
    int readed = -1;
    while((readed = fis.read(b)) > 0)
         md.update(b, 0, readed);
    fis.close();
    FileOutputStream fos = new FileOutputStream(args[1]);
    byte[] d = md.digest();
    StringBuffer sb = new StringBuffer();
    for(int i = 0; i < d.length; i++) {
         String str = Integer.toHexString(d[i] & 0xff);
         sb.append(str.length() < 2 ? "0" + str : str);
    fos.write(sb.toString().getBytes());
    fos.close();

  • Does any one have good idea about the backup and recovery georaster table?

    Does any one have good idea about the backup and recovery georaster table?
    Best Regards,
    Lin
    Edited by: ylin on 2009-10-10 上午2:07

    for backup and recovery, please follow the standard procedure of general database backup and recovery. you need to backup both the georaster table and all related RDT tables.

  • Dear Apple,please help me.the glitch and lags on games made me sad beause i am too love with my 4s. Why iOS 7 really made me sad...please help me.im beg for you.

    Dear Apple,please help me.the glitch and lags on games made me sad beause i am too love with my 4s. Why iOS 7 really made me sad...please help me.im beg for you.

    www.apple.com/feedback/iphone.html
    No one from Apple is listening on these forums.

  • A few questions about the ka790gx and dka790gx

    i have a few questions about the ka790gx and dka790gx , how much better is the dka790gx compaired to the ka790gx ? . how much difference does the ACC function make to overclocking etc , i plan on getting a phenom II 940BE or 720BE . i already have the ka790gx so would it be worth building another system using the dka790gx mobo , or should i keep what i already have and just change the cpu ?

    It's largely irrelevant what other boards had VRM issues other than the KA790GX - the fact is it died at stock settings. Since there is little cost difference between the more robust DKA790GX (or Platinum if you really need 1394) why bother with the proven weakling? There are other examples around of the KA not having a robust power section.  There's no way I would use even a 95W TDP CPU in the KA and absolutely not O/C.....!
    As for the credentials of Custom PC, I have generally found their reviews accurate and balanced, and echo my own findings where applicable. If a little too infrequent.
    The fact that the KA has such a huge VRM heatsink leads me to my other comments on the Forum, particularly regarding the "fudge" aspect:
    """Henry is spot on - the notion that adding a heatsink to the top of the D2PAK or whatever MOSFETS is effective is virtually worthless. The device's die thermal junction is the tab on the device back - which is always against the PCB pad. The majority of heat is therefore dissipated in to the board, and the fact that the epoxy plastic encapsulation gets hot is simply due to the inability of the heat to be conducted away from the device die via the tab. Not sure when Epoxy become an effective conductor of heat.... Good practice is to increase the size of the PCB pad (or "land" in American) such that the enlarged PCB copper area acts as an adequate heatsink. This is still not as effective as clamping a power device tab to an actual piece of ali or copper, but since the devices used are SMD devices, this is not possible. However, the surface area required to provide sufficient PCB copper area to act as a heatsink for several devices isn't available in the current motherboard layouts. Where industrial SBC designs differ in this respect is to place the VRM MOSFETs on the back of the PCB on very enlarged PCB pads - where real estate for components is not an issue.
    Gigabyte's UD3 2oz copper mainboards sound like a good idea, on the face of it. However, without knowing how they have connected the device tabs to where and what remains a mystery. I suspect it is more hype than solution, although there will be some positive effect. From an electrical perspective, having lower resistance connecting whatever to whatever (probably just a 0V plane) is no bad thing.
    The way the likes of ASUS sort of get round the problem is to increase the sheer number of MOSFET devices and effectively spread the heat dissipation over a larger physical area. This works to a degree, there is the same amount of heat being dissipated, but over several more square inches. The other advantage of this is that each leg of the VRM circuit passes less current and therefore localised heat is reduced. Remember that as well as absolute peak operating temperature causing reduced component life, thermal cycling stresses the mechanical aspects of components (die wire bonds for example) as well as the solder joints on the board. Keeping components at a relatively constant temperature, even if this is high (but within operating temperature limits), is a means of promoting longevity.
    For myself, the first thing I do with a seperate VRM heatsink is take it off and use a quiet fan to blow air on to the VRM area of the PCB - this is where the heat is. This has the added benefit of actively cooling the inductors and capacitors too....
    Cooling the epoxy component body is a fudge. If the epoxy (and thus any heatsink plonked on top of it) is running at 60C, the component die is way above that.....
    It's better than nothing, but only just."""

  • Help/advice needed SwinEvent thread and synchronization

    I am having a problem where my app keeps locking up. I have a swing application that receives asynchronous realtime messages from a server.
    On receiving these messages my views are required to update the components. I do this my calling a method with a synchronized block that updates the views components in a SwingUtilities.invokeLater clause.
    This seems to work fine. However, sometimes when I click a menu item/button the app locks up.
    I have put some debug in that shows me the synchronized block started but did not complete?!?!
    I think this tells me that the SwingEvent thread interrupted my external notification thread, and caused some sort of deadlock.
    If this is the case then why does my synchronized block of code not complete. I am not altogether sure what I should synchronize around.
    For example I am doing something like this>
    public void notify(Model model){
    if(model == null) return;
    synchronized(model){
    System.out.println("started");
    SwingUtilities.invokeLater(new Runnable(){
    componentA.setText(model.getName());
    System.out.println("ended");
    My output when it locks is like this
    started
    ended
    started
    ended
    started
    At this point the app is frozen.
    So I guess what I am asking is as follows>
    Is the SwingEvent thread interrupting my external notification thread?
    If so, why is the synchronized block not completing.
    What should I synchronize?
    Any help would be greatly appreciated.
    Dr Nes
    I can only assume that

    I am having a problem where my app keeps locking up. I have a swing application that receives asynchronous realtime messages from a server.
    On receiving these messages my views are required to update the components. I do this my calling a method with a synchronized block that updates the views components in a SwingUtilities.invokeLater clause.
    This seems to work fine. However, sometimes when I click a menu item/button the app locks up.
    I have put some debug in that shows me the synchronized block started but did not complete?!?!
    I think this tells me that the SwingEvent thread interrupted my external notification thread, and caused some sort of deadlock.
    If this is the case then why does my synchronized block of code not complete. I am not altogether sure what I should synchronize around.
    For example I am doing something like this>
    public void notify(Model model){
    if(model == null) return;
    synchronized(model){
    System.out.println("started");
    SwingUtilities.invokeLater(new Runnable(){
    componentA.setText(model.getName());
    System.out.println("ended");
    My output when it locks is like this
    started
    ended
    started
    ended
    started
    At this point the app is frozen.
    So I guess what I am asking is as follows>
    Is the SwingEvent thread interrupting my external notification thread?
    If so, why is the synchronized block not completing.
    What should I synchronize?
    Any help would be greatly appreciated.
    Dr Nes
    I can only assume that

Maybe you are looking for