Discussion
Sample67 is run - what will be the output?
import java.util.concurrent.Semaphore;
public class Sample67
{
public static void main(String[] args) throws InterruptedException
{
Semaphore permits = new Semaphore(1);
permits.acquire();
System.out.print(permits.availablePermits() + " ");
permits.release();
System.out.print(permits.availablePermits());
}
}
Answer: C
acquire takes a permit and blocks if none is available, so the count drops to zero; release returns one, taking it back to one. A semaphore counts rather than tracking an owner, which is why release may be called by a thread that never acquired.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development