subject

Assume that a finite number of resources of a single resource type must be managed. processes may ask for a number of these resources and -once finished-- will return them. as an example, many commercial software packages provide a given number of licenses, indicating the number of applications that may run concurrently. when the application is started, the license count is decremented. when the application is terminated, the license count is incremented. if all licenses are in use, requests to start the application are denied. such requests will only be granted when an existing license holder terminates the application and a license is returned. the following java class is used to manage a finite number of instances of an available resource. note that when a process wishes to obtain a number of resources, it invokes the decreasecount() method. similary, when a process wants to return a number of resources, it calls class manager{public static final int max_resources = 5; private int availableresources = max_resources; /***decrease availableresources by cuont resources.*return 0 if sufficent resources available,*otherwise return -1*/public in decreasecount(int count) {if (availableresources < count)return -1; else {availableresources -= count; return 0; }/* increase availableresources by count resources. */public void increasecount(int count) {availableresources += count; }}however, the preceding program segment produces a race condition. do the following: a.) identify the data involved in the race condition. (do not answer)b.) identify the location (or locations) in the code where the race condition occurs.(do not answer)c.) using java synchronization, fix the race condition. also modify decreasecount() so that a thread blocks if there aren't sufficent resources available and demonstrate that your soulution works. (answer and show that the program runs without the race condition) if you can get it to work with the code i provided below do the following up above. package thread; public class thread { public static final int max_resources = 5; private int availableresources = max_resources; public int decreasecount(int count){ synchronized(this) { if (availableresources < count) return -1; else { availableresources -= count; } return 0; // resource available // end of else }} // end function decreasecountpublic void increasecount(int count) { synchronized(this) { availableresources += count; }} // end function increase countpublic void main(string[] args){ int retval; system. out. println("thread (multi thread) demonstration to nullify race condition"); for (int i=1; i< =10; i++) { increasecount(2); retval = decreasecount(1); retval = decreasecount(1); }}} // end of class thread formerly called as manager class

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 18:00
File account.java (see previous exercise) contains a definition for a simple bank account class with methods to withdraw, deposit, get the balance and account number, and return a string representation. note that the constructor for this class creates a random account number. save this class to your directory and study it to see how it works. then write the following additional code: 1. suppose the bank wants to keep track of how many accounts exist. a. declare a private static integer variable numaccounts to hold this value. like all instance and static variables, it will be initialized (to 0, since it’s an int) automatically. b. add code to the constructor to increment this variable every time an account is created. c. add a static method getnumaccounts that returns the total number of accounts. think about why this method should be static - its information is not related to any particular account. d. file testaccounts1.java contains a simple program that creates the specified number of bank accounts then uses the getnumaccounts method to find how many accounts were created. save it to your directory, then use it to test your modified account class.
Answers: 3
question
Computers and Technology, 24.06.2019 01:30
Write a program that asks the user to enter the name of an input file. if the file does not exist, the program should prompt the user to enter the file name again. if the user types quit in any uppercase/lowercase combinations, then the program should exit without any further output.
Answers: 3
question
Computers and Technology, 24.06.2019 10:00
When writing a business letter, how many times can you use the same merge field in a document? once once, unless using the address block feature unlimited it will depend on the type of document you choose
Answers: 1
question
Computers and Technology, 24.06.2019 12:00
Jack is assisting his younger sibling mary with her mathematics assignment, which includes a study of the number system. jack explains to mary that whole numbers are counting numbers that could be used to record the number of fruits in a basket. which data type represents whole numbers? a.integers.b.floating-point numbers. c.strings.d.boolean
Answers: 1
You know the right answer?
Assume that a finite number of resources of a single resource type must be managed. processes may as...
Questions
question
Mathematics, 08.12.2019 10:31
Questions on the website: 13722367