CS FundamentalsHardProduct-company MCQ pattern
Assertion (A): A lazily initialised Singleton that checks if (instance == null) before creating the object can end up with two instances in a multithreaded program. Reason (R): Two threads can both see instance as null before either has assigned it.
- A. Both A and R are true and R is the correct explanation of A
- B. Both A and R are true but R is not the correct explanation of A
- C. A is true but R is false
- D. A is false but R is true
Correct answer: A. Both A and R are true and R is the correct explanation of A
Without synchronisation the check-then-create sequence is a race condition: both threads pass the null check and each creates an object. R is the exact cause; fixes include eager initialisation, a synchronised accessor, double-checked locking with volatile, or the holder-class idiom.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- How many of the following HTTP methods are idempotent by the HTTP specification: GET, PUT, DELETE, POST?
- Assertion (A): In a RESTful API, every request from the client must carry all the information needed to process it, such as an auth token…
- Match each HTTP status code with its meaning. P. 204 Q. 304 R. 409 S. 429 1. Too many requests (rate limit hit) 2. Request conflicts with…
- How many of the following are managed by the cloud provider (not the customer) in a PaaS offering such as a managed app platform? 1. The…
- How many of the following statements about serverless computing (FaaS, such as AWS Lambda) are correct? 1. Functions are typically billed…
- A web tier has two identical servers in parallel (each 99% available; the tier works if at least one is up), connected in series with a…