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 8 years ago.
Improve this question
which libraries we need for parallel programming in JAVA.
You simply start new threads, using the Runnable interface (or a lambda function, in Java 8) with the Thread constructor. Here's a really, really basic example:
Thread t = new Thread(() -> {
System.out.println("I'm in a different thread from the other code in this example");
});
t.start();
Then, of course, you have to handle all the issues around concurrency, which involves things like the synchronized keyword, various things (perhaps) from java.util.concurrent and its child packages, etc.
There's a Java tutorial on this here.
Related
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?
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.
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 7 years ago.
Improve this question
i tried to create a calc class which will have methords of mathematical operators which are not in java already..........
now after i created it ....if i wat to use this class functions i will have to make it a super class for my new program but .....if i want my new program to have multiple attributes of diffrent classes .........and simultaneously use calc functions........but i cant..............
why java doesnt have multiple inheritances.......what are its advantages and disadvantages?
tnx in advanced...
Java doesn't support multiple inheritance because of the "diamond problem" and other problems that arise from "increased complexity and ambiguity" as is explained in the wikipedia page on the matter
The creators of Java had a design goal of simplicity. That is why operator overloading with the added complexity of the "copy constructor" was also left out. That is why there is automatic memory management etc etc
most modern languages chose to discard this concept for the same reason.
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 7 years ago.
Improve this question
I want to maintain thread pool, and it should contain multiple jobs. Job has execute one after another
If you have a sequential execution of four jobs, you probably want to aggregate them into a single Runnable.
void run(){
job4(job3(job2(job1(inputs))));
}
It does not make much sense to schedule separate threads for the jobs (as only one of them can proceed at the same time).
You could submit that whole thing as one to an ExecutorService.
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.