Timeline for Thread-safe Iterator wrapper
Current License: CC BY-SA 3.0
9 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 19, 2015 at 14:31 | comment | added | h.j.k. |
There's Optional.ofNullable() which accepts null as an input argument, but will still throw NoSuchElementException upon doing a get() . If you want to mitigate that too, you can do a orElse(null) but at that point you should probably handle your null s separately, instead of 'passing through' the Optional wrapper.
|
|
May 19, 2015 at 12:40 | comment | added | GlenPeterson | Let us continue this discussion in chat. | |
May 19, 2015 at 12:38 | comment | added | GlenPeterson | what would it take to get you to review a larger work of code like github.com/GlenKPeterson/J-cicle feel free to contact me at my first name at organicdesign dot org. | |
May 19, 2015 at 12:32 | comment | added | rolfl |
@GlenPeterson - Depending on the visibility of the wrapped Iterator, yes (i.e. if the iterator was created inside the wrapper, then yes, otherwise I would have a dedicated instance private final Object lock = new Object();
|
|
May 19, 2015 at 12:31 | comment | added | GlenPeterson | Your comments are very helpful - thank you. You would put a synchronized block inside the nextBlocking() method that locked on the iterator, not on the containing object? | |
May 19, 2015 at 12:24 | comment | added | rolfl | About the 'null as the absence', what if the iterator returns a null value (a null in an ArrayList, for example...)? Optional should not treat null as a trigger for specific behaviour (and the Java one does not). | |
May 19, 2015 at 12:20 | comment | added | rolfl | The reference book for these types of things is "Java Concurrency in Practice" - It is still relevant, but is in need for a refresh.... I recommend borrowing a copy. | |
May 19, 2015 at 12:18 | comment | added | GlenPeterson | Optional treats null as the absence of a value. Sometimes that's OK, but I generally need to treat null as a present value. I need to think about your other advice more. A lot more. Is there a book that talks about stale memory access and multiple caches of the same data that you would recommend? | |
May 19, 2015 at 12:10 | history | answered | rolfl | CC BY-SA 3.0 |