Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

Exam 1z0-819 topic 1 question 81 discussion

Actual exam question from Oracle's 1z0-819
Question #: 81
Topic #: 1
[All 1z0-819 Questions]

Given:



Which makes class A thread safe?

  • A. Class A is thread safe.
  • B. Make foo and setB synchronized.
  • C. Make foo synchronized.
  • D. Make A synchronized.
  • E. Make setB synchronized.
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
ASPushkin
16 hours, 35 minutes ago
Selected Answer: B
answer: B public class A int a = 0; int b = 0; int c = 0; First of all, class A is thread-safe because declaring variables a,b,c is not private. It is possible to change the value of them within the package directly. C. Failed Reads and writes are atomic for reference variables and for most primitive variables (all types except long and double). Method setB does not establish a happens-before relationship, so it’s simply that there is no guarantee that the modification it causes is visible in other threads. All you get in this case is the guarantee that the it is atomic, but with no guarantees about the visibility of the (potentially) new value. So, that means that both methods should be synchronized
upvoted 1 times
ASPushkin
16 hours, 34 minutes ago
First of all, class A is not thread-safe because declaring variables a,b,c are not private.
upvoted 1 times
...
...
d7bb0b2
6 months ago
B is correct!
upvoted 1 times
...
Omnisumem
10 months ago
Selected Answer: B
Obviously B.
upvoted 1 times
...
Stavok
11 months, 3 weeks ago
Selected Answer: B
The correct answer is B. Make foo and setB synchronized. Class A is not thread-safe because the methods foo and setB can be called concurrently by multiple threads, leading to race conditions when accessing and modifying the shared variables a, b, and c. To make class A thread-safe, both methods foo and setB should be made synchronized. This ensures that only one thread can execute either method at a time, preventing race conditions.
upvoted 2 times
...
tmuralimanohar
1 year ago
Answer: B
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
ex Want to SAVE BIG on Certification Exam Prep?
close
ex Unlock All Exams with ExamTopics Pro 75% Off
  • arrow Choose From 1000+ Exams
  • arrow Access to 10 Exams per Month
  • arrow PDF Format Available
  • arrow Inline Discussions
  • arrow No Captcha/Robot Checks
Limited Time Offer
Ends in