Questions from Effective Java book(Joshua Bloch) [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I started reading Effective Java(Joshua Bloch) and I'm currently at Chapter 3.
Each instance of the class is inherently unique. This is true for classes that
represent active entities rather than values, such as Thread.
I don't understand which this is particularly mentioned the Thread class.
I would be glad if you can help

The Thread class is a prime example of a class that represents an active entities. Each thread is a "thread of execution of a program" (Oracle Docs). In other words, the Thread class models an active computation. It would not make much sense to treat a thread as a value. Two threads instantiated with the same initial state may act differently. That is why multithreading bugs, like deadlock, only sometimes occur.

Related

Safely edit the Database with multiple threads in java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am trying to learn multi-threading in java.
Suppose I have a very big application with 100 running threads trying to execute a synchronized method which inserts a row in database.
As, the method is synchronized so only one thread will get the lock for that method and rest 99 will wait.
Only 1 thread is able to edit the Database and rest will be waiting. It seems a slow process. As all the threads will be editing the DB one by one. Is there any other way or concept to safely edit the database in a faster way?
i will recommend u to read about isolation level in transaction to handle some cases in concurrent application https://en.wikipedia.org/wiki/Isolation_(database_systems), sometimes is handles by default.
if for isntance u only adding new rows in table u shouldn't care about it and remove synchronized

Why have some threading problems been solved without extending java.lang.Object? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
Some threading problems were solved without extending java.lang.Object.
The methods wait(), notify() and notifyAll() are implemented on Object, which seems to me not to be the best decision since it pollutes the class's interface. It affects all classes in Java, which I think should have been avoided.
Next, the synchronized block takes an instance of type Object, allowing us to accidently pass shared instances (e.g. String), which can cause problems. They could have crafted a class Mutex/Lock in order to avoid this.
I wonder whether this comes with any technical advantages - e.g. performance - or whether it is just bad design? Is there somewhere an official documentation, e.g. a JEP or something similar - on why the Java language designers decided to work directly with java.lang.Object?

Need of SingleThreadPool in Java? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a few questions regarding ExecutorService.
In what cases we should use newSingleThreadExecutor() than others and Why?
Can you tell me the real use case of having SnewSingleThreadExecutor()?
If we have a single thread either from (newSingleThreadExecutor() or newFixedThreadPool(1) or newCacheThreadPool(1)) Do we still need to check for Thread Safety?
Why do we need newSingleThreadExecutor() if we can already create a single thread using newFixedThreadPool(1)
When you don't want tasks to run in parallel because of common data.
Swing's Event Dispatch Thread. It is not called executor, but in fact it is, just its execute method is called invokeLater.
It depends on what data you access. If that data can be accessed outside the tasks running on this executor, then yes. It does not depend of how you built your executor.
We do not need. I don't know what SingleThreadPool do you mean - there is no such class in Java runtime libarary.

understanding what java 11 dynamic class-file constants [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm trying to understand the java 11 (JEP 309) dynamic class-file constants, it looks like an interesting feature.
and I google it, but I didn't find detailed articles (if you know any please share it) I just find this one by Rafael Winterhalter, but I still have some questions :
does this feature will make it possible to extend the types of constants that could be added to the pool (actually the pool could hold primitive and string values- correct me if I'm wrong)
in the article it is said that dynamic constant is generated as a result of invoking a bootstrap method, and that this method need to be referenced from the class’s constant pool, but how to do it (how to reference this method from class’s constant pool??)??.

Can differences between 2 copies of the same serialized object be determined? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Suppose we possess 2 serialized copies of an object.
Q1. I wanted to know whether the state of an object can be compared with its prior state.
Q2 If yes, can we find out precisely which class variables have been changed ?
Q3 If the answer to the 2nd question is yes, can we perform some sort of "synchronization" to change only the modified class variables ?
One way to check state of object is using
PropertyChangeSupport and PropertyChangeListener
You can go through the below link for how to write PropertyChangeListener for particular bean.
http://docs.oracle.com/javase/tutorial/uiswing/events/propertychangelistener.html

Categories

Resources