r/java • • Mar 14 '18

Concurrent Java: Low scalability, the risk of deadlocks or garbage creation, you can not avoid all

http://vmlens.com/articles/tradeoffs_concurrent_programming/
2 Upvotes

21 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Mar 15 '18

[deleted]

1

u/duhace Mar 15 '18

please describe your immutable list for which copying is no longer necessary on one of either append or prepend.

0

u/[deleted] Mar 15 '18

[deleted]

1

u/duhace Mar 15 '18

first of all, this datastructure is expensive to traverse, even compared to normal lists, and second, i doubt it can even be considered a list considering it injects valid data (null) to indicate that there is no data, when append(null) would in fact be a valid argument.

but you're right, it does manage to avoid copying, just in a terrible way that is not worth it over a standard singly linked list.

0

u/[deleted] Mar 15 '18

[deleted]

1

u/duhace Mar 15 '18 edited Mar 15 '18

Saying it's O(n) like a linked list is disingenuous, since O notation only describes the rate at which the difficulty of an operation grows. Traversal is much more complicated than a linked list, and requires constructing another (temporary) datastructure to do in one pass, or requires a non-tail call recursive function to do in two passes.

There is no law that says null must always be a valid value. If you want it to be, just use Optional <T> instead of T, or you could have two sub classes (one for prepend one for append).

We're talking java here, where null is a valid value for any generic value. So yeah, you have to take that into account.

→ More replies (0)