Free Essay

Discussion

In:

Submitted By zhubinlin3
Words 613
Pages 3
Four people are selling tickets at the same time. The number of all tickets is 40. Each ticket only can be sold one time. import java.util.concurrent.locks.ReentrantLock; public class ThreadTest implements Runnable { int tickets = 40; ReentrantLock lock = new ReentrantLock(); public void run() { while (true) { lock.lock(); try { if (tickets > 0) { System.out.println(Thread.currentThread().getName() + "is selling NO."+ tickets + " ticket."); --tickets; } lock.unlock(); } catch (Exception e) { lock.unlock(); } } } }

public class Demo1 { public static void main(String[] args) { ThreadTest tt = new ThreadTest(); Thread t1 = new Thread(tt); Thread t2 = new Thread(tt); Thread t3 = new Thread(tt); Thread t4 = new Thread(tt); t1.start(); t2.start(); t3.start(); t4.start(); } }

result: Thread-0is Thread-0is Thread-0is Thread-0is Thread-0is Thread-0is Thread-0is Thread-0is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is Thread-3is

selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling selling

NO.40 ticket. NO.39 ticket. NO.38 ticket. NO.37 ticket. NO.36 ticket. NO.35 ticket. NO.34 ticket. NO.33 ticket. NO.32 ticket. NO.31 ticket. NO.30 ticket. NO.29 ticket. NO.28 ticket. NO.27 ticket. NO.26 ticket. NO.25 ticket. NO.24 ticket. NO.23 ticket. NO.22 ticket. NO.21 ticket. NO.20 ticket. NO.19 ticket. NO.18 ticket. NO.17 ticket. NO.16 ticket. NO.15 ticket. NO.14 ticket. NO.13 ticket. NO.12 ticket. NO.11 ticket. NO.10 ticket. NO.9 ticket. NO.8 ticket. NO.7 ticket. NO.6 ticket. NO.5 ticket. NO.4 ticket. NO.3 ticket. NO.2 ticket. NO.1 ticket

In main process, I create object tt and use four threads to run it. When threads run

to the while loop they need a lock to continue, but only one of them can get the lock at the same time. All the threads can print and minus 1 one by one. Suppose thread 0 get the lock. It can execute the below code but other threads have to keep trying to get lock until thread 0 release the lock. The thread 0 would print something and minus one from the number of tickets, and then release the lock and try to get lock again. Usually a thread tends to get the lock continuously like following. Thread 0 ✕ ✕ ✕ ✕ ! ! 。。 。 If without the lock and unlock, for example CPU switch to thread 0 when ticket left one, which is more than zero. So it prints selling No.1 ticket. However, before thread 0 execute ticket -­‐-­‐ the CPU switch to thread 1 and ticket = 1 is bigger than 0, thread 1 prints selling No.1 ticket again. Therefore, the same ticket may be printed many times. At that time, because both thread 0 and thread 1 have past the judgment (ticket >0), they both would minus one from the number of tickets. The number of ticket would become -­‐1. That is why there would be some negative numbers.

We should use the lock carefully to avoid dead lock, so we always use try-­‐catch or try-­‐finally to throw exception, which protect the process go ahead. Thread 1 ! ! ! ! ✕ ✕ 。。 。 Thread 2 ! ! ! ! ! ! 。。 。 Thread 3 ! ! ! ! ! ! 。。 。

Similar Documents

Free Essay

The Discussion of Discussion

...3. Explain the meaning and significance of the omnipotence of God. Verses: - Job 11:7-9 - “Can you fathom the mysteries of God? Can you probe the limits of the Almighty? They are higher than the heavens above—what can you do? They are deeper than the depths below—what can you know? Their measure is longer than the earth and wider than the sea.” - Matthew 19:26 - “Jesus looked at them and said, ‘With man this is impossible, but with God all things are possible.’” - Psalm 147:5 - “Great is our Lord and mighty in power; his understanding has no limit.” Quotes: “We cannot have a right conception of God unless we think of Him as all-powerful, as well as all-wise. He who cannot do what he will and perform all his pleasure cannot be God. As God hath a will to resolve what He deems good, so has He power to execute His will.” - Arthur W. Pink “His Omnipotence means power to do all that is intrinsically possible, not to do the intrinsically impossible. You may attribute miracles to Him, but not nonsense. There is no limit to His power….It remains true that all things are possible with God: the intrinsic impossibilities are not things but nonentities. It is no more possible for God than for the weakest of His creatures to carry out both of two mutually exclusive alternatives; not because His power meets an obstacle, but because nonsense remains nonsense even when we talk it about God.” - C.S. Lewis “Clearly, the Scripture tells us that we lack the capacity to grasp God's infinite...

Words: 975 - Pages: 4

Free Essay

Discussion

...187 - Discussion & Application Papers (2 @ 25 Points each) These papers are meant to help student review the new materials learned and apply to cases to improve their understanding and appreciation of various concepts, terms etc. Such papers also make the task of preparing for exams easier as most of the materials you need to know would have been reviewed periodically, instead of the conventional cramming. Discussion & Application Papers are each worth 25 points. Each student needs to select 1 out of the two cases 1A OR 1B. Both these cases Nike and Ikea are available in the textbook. Each student must complete Case 2 due on Apr 28th. This case will be available on the Harvard Business Case website. The instructions to download this case are available on page 2 of this document. The assignments are due in the drop box, on the days indicated in the schedule, at the beginning of class time. You need to make two copies so that you can retain one for your own use during the class discussion phase and hand the other to the instructor for grading purposes. The paper should incorporate: 1. Your analysis of the Case 2. Generally the last question or two are the opinion questions so always respond to those question/s. In addition, you may select up to two questions. Thus respond to a minimum of three and maximum of four questions. You can do so in bullet form or as paragraphs. 3. Apply key concepts, definitions from all chapters and lectures discussed in class until this discussion session;...

Words: 634 - Pages: 3

Free Essay

Discussion

...Week 2 Discussion Algebra review. Please respond to one of the following questions: •Imagine you are tutoring a classmate in the four (4) algebraic processes. Outline each procedure in the process of solving algebraic equations and then try to use your outline as a guide to teach a follow student. •The author of your textbook indicates, “If you add percents, you often obtain incorrect results.” Explain in your own words what kinds of errors contribute to inaccurate percent results. •Determine what makes solving an equation with two (2) variables different than one (1) variable. Week 4 Discussion Simple and compound interest. Please respond to one of the following questions: •Explain methods for calculating credit card interest and your reason for going with a particular method. •What are the factors associated with math that you need to know about in order to obtain a mortgage loan. List at least five (5) factors and provide a rationale for those you selected. •A bottle of water cost one dollar in Chicago. However, the same bottle of water cost five dollars in the Mojave Desert. Consider the definitions of cost and value and explain the difference as to why the bottle of water in the desert might be more valuable. Week 5 Discussion Set operations and Venn diagrams. Please respond to one of the following questions: •Create a story problem that demonstrates how a Venn diagram could be used to illustrate combined operation with sets. •Give two (2) reasons why...

Words: 410 - Pages: 2

Free Essay

Discussion

...This discussion will enable us to lay some of the theoretical groundwork for communication and public speaking. Let's begin by exploring the basics. How do you define the term communication? Take a few minutes to go through the "Is This Communication?" activity included in this week's lecture material and report your results. I personally define communication as any individual trying to convey his/her thoughts to someone other than his/her self. Although I scored average in the results of my Communication Anxiety Report and Analysis, I barely made over the hump of the very low CA. I am not sure what it means right now but I am okay with it. I should improve by the end of the course. We are in the same page with this one. But as I mentioned in my original post that I am comfortable with final report of average even though I barely made it over the very low CAR. The good news is we are taking this class and I am positive that we are going to improve our scores. According to Wikipedia, Public speaking is the process and act of speaking or giving a lecture to a group of people in a structured, deliberate manner intended to inform, influence, or entertain a listening audience. Public speaking is commonly understood as face-to-face speaking between individuals and an audience for the purpose of communication. It is closely allied to "presenting", although the latter is more often associated with commercial activity. Most of the time, public speaking is to persuade the audience;...

Words: 463 - Pages: 2

Free Essay

Discussion

...Module 3 Discussion Read Case 4-1 (“JetBlue Airways: Regaining Attitude”) in Corporate Communication and respond to the following: •Clearly and concisely identify what was the most significant business problem JetBlue faced and support your claim. •Assess and identify the critical constituency issues. •Articulate what you believe are the three most desirable outcomes. •Discuss at least three communications best practices implemented by JetBlue. Post your initial response to the discussion question no later than Thursday 11:59 PM EST/EDT. Post responses to at least two classmates no later than Sunday 11:59 PM EST/EDT The most significant business problem JetBlue faced during the 2007 crisis was inadequate communication. In this case JetBlue CEO David Neeleman stated, “Among the primary culprits: inadequate communication protocols to direct the company’s 11,000 pilots and flight attendants about where to go and when; an overwhelmed reservation system; and a lack of cross-trained employees who could work outside their primary area of expertise during an emergency” (Argenti, 2011, p.105).JetBlue spokesperson Sebastian White stated, “We thought there would be these windows of opportunities to get planes off the ground, and we were relying on those weather forecasts” (Argenti, 2011, p.104). This risk taking by JetBlue ultimately lead to several critical constituency issues. Nine JetBlue jets were forced to sit idle on the tarmac for more than six hours....

Words: 660 - Pages: 3

Free Essay

Discussion

...In our discussions over the following weeks, we will practice applying virtual team management techniques to a sample virtual team project you will be leading. This week each of you needs to propose a virtual team project that you will be using in subsequent discussions (I will refer to this project as project X from now on). Please pick a virtual team project and describe it: the project team composition, locations of team members, the project goals, timeline and deliverables. Virtual Team Project: Planning a seminar that is geared towards real estate investors who are looking to network, learn new strategies and showcase investment opportunities. Project Team Composition: The team consists of 8 investors who have both the expertise needed for task attainment and skills needed for proper team functioning. The team was handpicked by the Central Florida Realty Investors (CFRI) to organize, facilitate and execute the seminar. Location of Team Members: The team is spread out throughout the United States, as follows: Florida (2), Chicago (1), New York (2), California (2), and Washington (1). Project Goals: The goal of this project is to host a seminar that will help current or potential investors to learn more about investing, make money and have fun doing it. At the seminar our guests will learn: * How to become financially independent and build long-term wealth through real estate * How to use OPM (Other People’s Money) to accumulate a fortune over time * How...

Words: 315 - Pages: 2

Premium Essay

Discussion

...employees” “supports for elderly and disabled which can guarantee them the care they need people with preexisting condition to be covered” “protect all Americans’ choice of doctors and end lifetime limits on the care consumers may receive” “expand eligibility for Medicaid” The patient protection affordable act emphasizes several short- and long-term provisions. I believe some of the long-term provisions needed to improve the U.S healthcare system are to make sure every U.S citizen to have health insurance, assure elderly as well as disabled to have healthcare coverage and provide them with the care they need, protect all Americans’ choice of doctors and ensure people with pre-existing conditions to be eligible to have health insurance. Discussion 2: There are many Americans that support the healthcare bill but many others are against it. I think that the patient protection and affordable healthcare act should not be repealed but should be modified to fix some issues such as the increase in taxes on medical companies and Medicare taxes. Response1: While health care reform is mainly about expanding access, ways to improve quality of care include promoting access to primary and preventive care, improving patient-clinician communication and staffing of experienced workers. Also, enforcing regulations governing managed care organizations, increasing financial support to deal with health care workforce shortage, reducing...

Words: 492 - Pages: 2

Premium Essay

Discussion

...Discussion – 6/10/2013 Regarding emotional intelligence as one of the leadership traits, I believe Obama’s campaign slogans of "Yes We Can" and "Change we can believe in" are what stirred the desperate Americans emotionally. And, Obama’s ability to sense the despair, frustration and urgency of Americans is what connected him emotionally to the public and led to the historic win in 2008. Yes, I do believe in leaders maintaining transparency. And that can be attained with two way open communications between the leaders and the followers. This enables the leader not only to gain trust and confidence of the followers but also motivates the followers to develop a team approach with the goal of a better and successful future. Speaking of leaders such as Mahatma Gandhi, what strikes me most, but, not addressed in the referred text book, is how simple and humble he was. By having such great attributes, he was not only able to gain the trust of his followers, but also able to lead by example. I agree that employees should not be micro-managed by their supervisor. There should be a basic standard of trust and confidence established in the work environment such that the employees feel motivated to be productive beyond expectation. When I think of leaders, many strike my mind. Few of them are Mahatma Gandhi, Margaret Thatcher, Martin Luther King Jr., Abraham Lincoln, President Obama, etc. And then, there are other leaders in our daily lives who do not make global head lines; such as...

Words: 583 - Pages: 3

Premium Essay

Discussion

...Week 6 Discussion Question 1 Rausell Harvey Ashford University PSY 600 Introduction to Graduate Study in Psychology Instructor Kathryn Morris January 11, 2016 Imagine someone and or the media painting an image of you or your illness in the wrong way or light. How would that make you feel? Being judged unfairly or falsely because you have a mental illness is wrong, period. The bad stereo types proceed out in such representation; mentally ill people as incapable, threating, messy, dirty and unworthy. The media have gradually become aware of these detrimental portrayals. I started watching this show on A&E called Intervention. Is a Rehab reality show that showcase extraordinary causes of addiction and substance use; were their family and friends get together and confront their loved ones. There’s no quality metric for improvement, however one consider the excessive recidivism of drug delinquents heading back to prison, the persistent relapsing of individuals whom proceeded through community based rehabilitation programs and any person who’s fooled with a junkie in their personal life. The problem is that this is a reality show and it not really about intervention it’s about ratings. Reality shows often choose people for the show that will boost ratings, act a fool, fight argue etc. This tend to open up ethical standards when choosing people for the show. This documentary / reality show shows the day and life of addicts. It takes the addicts and their families...

Words: 409 - Pages: 2

Premium Essay

Discussion

...Discussion The results of the experiment did not support the created hypothesis that the poisonous enzyme PTU (Phenylthiourea) was a competitive inhibitor. In the experiment to test whether PTU was competitive a catechol oxidase substrate was added to the solution to determine it’s inhibition. As more of the substrate was added, no reaction occurred and the substance remained consistently clear. However, the results indicated that the catechol that was used continued to be inhibited by the PTU. Due to this inhibition, catechol oxidase was present in potatoes and the results suggested opposite from the hypothesis. Enzyme inhibitors are compounds that counteract substrate-enzyme interactions. Two classes of enzyme inhibitors are competitive and noncompetitive. Enzyme inhibitors work as one of the major controls in the biological systems. Competitive inhibitors act in the spot that are meant to be for it’s intended substrate. At any given moment enzymes may bind to its inhibitor, the substrate or neither. They are unable to bind to both at the same time. This inhibition competes with the substrate for binding sites on the enzymes. However, a competitive inhibitor is reversible if the concentration of the substrate is raised to high levels while the inhibitor is constant. Noncompetitive inhibitors do not compete for its position in the active site. It decreases the activity of the enzyme and binds equally even if it’s bound to the substrate or not. This...

Words: 543 - Pages: 3

Premium Essay

Discussion

...I support your point about immigration barrier. Immigration status is a serious imposing problem. A lot of non-immigrants are hard working and can even have positive impact on the society if they have good health. I know a lot of registered nurses in the US that left for other countries because they are not eligible to work and have insurance. Some even got sick and some died because of fear of deportation and lack of insurance. you made a great point and I strongly support the notion of creating a program that can help the non immigrants or other un-insured people. I suggest that the government should provide adequate information and awareness about such health programs; making people understand that regardless of their health, immigration and financial status, they are still entitled to some health benefits. Lots of people die due to the fear of their immigration status, lack of funds and lack of awareness of the disease(s) they are afflicted with and its management. Such programs should consist of clinical educators that will enlighten individuals about their health, physical well being, prevention and management of diseases and little or no cost. Language barrier is a major barrier. In some cases, patients cannot fully express themselves about the signs and symptoms that they have which invariably lead to wrong diagnosis or poor treatment of such illness. All hospitals should be able to provide interpreters at any given time. Care givers should be calm whilst dealing with...

Words: 594 - Pages: 3

Free Essay

Discussion

...Tax policy topics are important to everyone. Hopefully, this discussion will give you an opportunity to deliberate on a topic that often generates a lot of comment as government balances it role with community and business interests. When the City of Philadelphia first proposed helping the Phillies build a new facility, two center city sites were proposed. The current South Philadelphia location was finally chosen after much debate over the center city sites. Read both chapters and come to class prepared to discuss the tax policy topic. Week 1 - Public tax policy is an important topic for all of us. At some time you may be asked to provide your comments on a tax issue. Let's discuss the following question. Revenue bonds are municipal bonds that are secured by specific income of the issuer. Furthermore, states, cities, and municipal subdivisions issue municipal bonds and their purpose is to fund municipal projects, such as housing, hospitals, lighting systems, parking ramps, stadiums, factories, sewer systems, and dozens of other community enterprises. Revenue bonds are municipal bonds that finance income-producing projects. The income generated by these projects pays revenue bondholders their interest and principal. Projects funded by revenue bonds serve only those in the community who pay for their services. (Morning star) From the perspective of the mayor of Philadelphia. PROS * Sports serve as a municipal amenity that can create social capital and improve...

Words: 669 - Pages: 3

Premium Essay

For Discussion

...did Marchionne display an entrepreneurial orientation while trying to turn around Chrysler? Explain. He took a risk by moving junior executives up in the organization a level or two. 5. How would you evaluate Marchionne’s technical, conceptual, and human skills? Discuss your rationale. Technical- he knew exactly how he was going to fix the problem by bringing his Fiat management style to Chrysler. Conceptual- he saw he had to make changes from the old ways the company operated and make quick decision- making to get the head in the automobile world globally. Human skills- he moved on the fourth floor to show he want to work close to his people, showed respect, he help build self-confidence and grow as professionals. Chapter 2: For Discussion 1. To what extent is Providence using evidence-based management? Do you think that this is a good way to run a hospital? Explain your rationale. To measure and collect data. Yes. It opens the door for more input and new ideas to solutions. 2. To what extent are the managerial practices being used at Providence consistent with principles associated with management science and operations management techniques? Discuss. One is by keeping scorecards to...

Words: 458 - Pages: 2

Premium Essay

Discussion

...Week Two’s Discussion Questions Question#1 Job descriptions are needed in an organization because it provides job information and criteria practices that help to select the best candidates. In addition, job description ensures that applicants have a full understanding of what is expected of him or her. A job description is a good tool that assists employers with explaining and clarifying the job duties, responsibilities, and reporting guidelines to its future candidates. Additionally, job descriptions develop agreements between employer and employee about business goals, objectives, and communication measurements that will enhance working conditions. Moreover, job descriptions helps employers in recognizing risks and hazards in working conditions, and develop methods that improves threats. A job description helps to organize and align an organization infrascture by developing job specifications that is suitable to the organizations practices, and gathering information about its performances that will increase productivity. When job specifications are built, it business outcomes are tied simultaneously in accordance to its relevance. In other words, job descriptions define roles and responsibilities, if implemented, could improve the business strategy. Job descriptions are used to identify operation gaps or requirements by the entity because it enables managers to devise strategies, and implement actions for improvements. Organizations utilize job descriptions to help with...

Words: 662 - Pages: 3

Free Essay

Discussion

...Module 4 Discussion Questions Answer each of the following question with a substantive response. A substantive response is one that: 1) is a minimum of 125 words, 2) is a thoughtful and thorough response to all aspects of the question, 3) accurately applies information from the course material, and 4) utilizes appropriate grammar. You will be graded based upon length and grammar, your insight into the issue addressed, and demonstration of knowledge of the course material as found in the book and elsewhere. Please check the formatting before submitting your response. 1. Read the following scenario: Is there an ethical issue here? How should she act in this situation? How can she convince the marketers? Be sure to explicitly apply the rules of ethical decision-making in determining your answer. “A marketing team presents a children's cereal brand manager with a ‘Less Sugar’ ad campaign for three of her brands.  Large print and dynamic type on the package exclaiming ‘75% LESS SUGAR’ will catch the parent’s eye and increase sales. Concerned about their children’s weight gain, parents will purchase the cereal.  The carbohydrate content of the less sugar product, however, is the same as high sugar version, at best only10 fewer calories per bowl, so it offers no weight loss advantage.  The brand manager’s immediate reaction is ‘This marketing campaign is unethical.’” (Hamilton, J.A., 2009). Yes there is an ethical issue in this scenario. The marketing team is advertising...

Words: 759 - Pages: 4