r/programming • • Feb 22 '15

Java Makes Programmers Want To Do Absolutely Anything Else With Their Time

http://www.forbes.com/sites/quora/2015/02/21/java-makes-programmers-want-to-do-absolutely-anything-else-with-their-time/
35 Upvotes

636 comments sorted by

View all comments

Show parent comments

3

u/[deleted] Feb 22 '15

Java has way better standard library support for concurrency though. From what I can tell, C# lacks an equivalent for ConcurrentLinkedQueue and ConcurrentSkipListMap. Also no ForkJoinPool or Phaser.

3

u/Eirenarch Feb 22 '15

How is a ForkJoinPool different from a TaskScheduler - https://msdn.microsoft.com/en-us/library/system.threading.tasks.taskscheduler(v=vs.110).aspx

Also why do you care if your ConcurrentQueue is a linked list or not? .NET's ConcurrentQueue seems to be a linked list of small arrays but this is an implementation detail that I do not expect anyone to care about.

3

u/[deleted] Feb 22 '15

The ForkJoinPool uses a pretty great scheduling algorithm, which allows for better cache locality and better handling of blocking IO.

The ConcurrentLinkedQueue implementation is wait-free, which is very important in soft real-time applications. The ConcurrentSkipListMap implementation allows truly concurrent reading and writing, using compare-and-swap.

In comparison, all concurrent collections in C# seem to use locks. Most applications don't need the distinction, but some (e.g. finance, game servers, ...) do need them.

1

u/Gurkenmaster Feb 22 '15

It's not a proper queue in my eyes if it uses locks. It's a toy.

1

u/Eirenarch Feb 22 '15

The ForkJoinPool uses a pretty great scheduling algorithm, which allows for better cache locality and better handling of blocking IO.

So does the Task Scheduler (it does work stealing). As far as I know they are pretty similar.

ConcurrentQueue in .NET is also lock free and it is essentially a linked list. If anything it looks more advanced since it uses Segments instead of items which may help with cache locality. In any case I don't think they did the additional work to introduce segments if it didn't improve performance over pure linked list.

1

u/[deleted] Feb 22 '15

Those 2 data structures don't exist in the .Net framework, indeed.

Regarding parallelism in general, the TPL (and async/await from C# 5) address all parallel/asynchronous needs.

And with support for delegates as first-class values you write much less code.