Earlier quoted context omitted.
The problem for novices is that a program that behaves correctly looks a lot like a correct program. Until one day it doesn’t. And because you’re in production and getting random spurious failures, the panicked (but common) reaction is to wrap every shared resource in a synchronized block. Which makes an incorrect implementation worse but possibly correct.
What's a better alternative to synchronizing access to shared resources?
Java Concurrency – Understanding the Basics of Threads
51–60 of 86 posts
Re: Java Concurrency – Understanding the Basics of Threads
#52Earlier quoted context omitted.
Novices don't build working concurrent systems of any kind with any toolkit, period. Concurrency is hard and thinking all the "concurrency problems" go away with some message passing is both ludicrous and dangerous. Fearless concurrency can only be attained through understanding, not by thinking all your problems went away because you're using a "cool approach".
It's pretty easy to make the leap from individual SQL statements to SQL statements which are wrapped in a transaction.
Re: Java Concurrency – Understanding the Basics of Threads
#53Earlier quoted context omitted.
A computer is a mutation machine, you cannot escape mutation by hand-waving it away. If you are writing programs in which you can achieve concurrency without threads and shared memory, it’s because you’re building on the shoulders of all the engineers who didn’t hand-wave it away. Many of us, due to product requirements, don’t have the luxury of using higher level abstractions like that.
And yet we're comfortable hand-waving GOTO away - that is, not calling computers GOTO machines.
Re: Java Concurrency – Understanding the Basics of Threads
#54With Futures and Executors/ExecutorServices I find that I rarely ever need to use raw Threads these days. Most of the thread-safety issues commonly encountered are eliminated with this approach as well.
Re: Java Concurrency – Understanding the Basics of Threads
#55Earlier quoted context omitted.
It's pretty easy to make the leap from individual SQL statements to SQL statements which are wrapped in a transaction.
Excellent example for making my point, since "just wrap it in a transaction" usually leads to concurrency bugs like the beloved lost update.
Re: Java Concurrency – Understanding the Basics of Threads
#56I'm not a Java developer, but isn't RxJava the current best practice around managing concurrency in Java? I thought the consensus was that manually dealing with thread creation is too error-prone and unmanagable.
Re: Java Concurrency – Understanding the Basics of Threads
#57Earlier quoted context omitted.
What's a better alternative to synchronizing access to shared resources?
Treat it like GC and don't leave it up to the programmer.
Re: Java Concurrency – Understanding the Basics of Threads
#58Earlier quoted context omitted.
If the resource is shared and being accessed from many threads and is both written to and read from then it is the correct behavior to to lock it with the proper type of lock at access time. Depending on resource it might be possible to split it into few with more granular access. As for novices: they are called that for reason and supposed to be under supervision rather than allowed running wild.
Why is this being downvoted? It's the truth. HN needs to only allow downvotes that have an accompanying explanation comment.
Re: Java Concurrency – Understanding the Basics of Threads
#59Earlier quoted context omitted.
It's pretty easy to make the leap from individual SQL statements to SQL statements which are wrapped in a transaction.
Excellent example for making my point, since "just wrap it in a transaction" usually leads to concurrency bugs like the beloved lost update.
Re: Java Concurrency – Understanding the Basics of Threads
#60Earlier quoted context omitted.
Novices don't build working concurrent systems of any kind with any toolkit, period. Concurrency is hard and thinking all the "concurrency problems" go away with some message passing is both ludicrous and dangerous. Fearless concurrency can only be attained through understanding, not by thinking all your problems went away because you're using a "cool approach".
Surprisingly this is what the akka framework promises : Message passing and immutability of objects.