Timeline for Implementation of java.util.stream.Stream (and friends) that reads lines from the internet without requiring you to manage the resources
Current License: CC BY-SA 4.0
16 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 21 at 22:15 | comment | added | davidalayachew | @throx Ok, you're talking about Runtime Warnings. I can try and look into that, ty vm. | |
| Oct 21 at 5:29 | comment | added | throx | @davidalayachew If you want to detect it more easily, wrap your managed resource in something that dumps a warning in the finalizer if close() isn't called. Bonus points for capturing the thread on allocation (in non-production) to make it even easier to find. | |
| Feb 13 at 11:24 | comment | added | davidalayachew | Just an update -- we finally shipped this feature to PROD just recently. I went with what you mentioned -- try-with-resources. As expected, they kept forgetting to use it, but we hammered most of the bugs. Thanks again for pushing for the idiomatic way -- it ended up being the better choice in the end. | |
| Mar 9, 2024 at 0:39 | comment | added | Florian F | When I said "shared between threads", I meant one thread opens the stream and later another thread picks up the work. Or maybe never shows up. | |
| Mar 8, 2024 at 14:57 | comment | added | Clement Cherlin |
@FlorianF Java provides a way to parallelize stream operations and close the stream when the operations complete. try (Stream<X> sharedStream = getStream()) { List<Results> = sharedStream.parallel().map(this::doStuff).toList(); }
|
|
| Mar 8, 2024 at 7:15 | vote | accept | davidalayachew | ||
| Mar 8, 2024 at 7:14 | comment | added | davidalayachew | Ok, I did my fair share of digging. I don't like it, but it seems like using various IDE plugins will be the solution out of this. It's not a very good solution at all -- this is something that should be provided by Java, not IntelliJ or a maven plugin. Regardless, it is a better solution than what I proposed, so I accept this answer. | |
| Mar 8, 2024 at 6:09 | comment | added | davidalayachew | Oh, I see the answer has been updated in response to the comments. I guess I will dig into those tools sooner rather than later. I still do think that the language should have better support for detecting resource leaks. | |
| Mar 8, 2024 at 6:02 | comment | added | davidalayachew | @MTilsted Thank you for your suggestion. If all else fails, I will look into your solution. | |
| Mar 7, 2024 at 23:10 | history | edited | Reinderien | CC BY-SA 4.0 |
more comments
|
| Mar 7, 2024 at 21:07 | comment | added | Florian F | David specifically said he wants a stream that does not require an explicit close (and try-with-resources is syntaxic sugar to do exactly that). For instance I would like to consume a stream shared between threads. The stream should autodetect when it is not used any more. | |
| Mar 7, 2024 at 18:35 | comment | added | MTilsted | @davidalayachew Most software development solutions can detect AutoCloseable not being closed. And Eclipse can for example be configured to make it an compile time error, not to close an AutoCloseable object. | |
| Mar 7, 2024 at 14:04 | comment | added | davidalayachew | I should edit my post to communicate why I did that specifically. Doing it now. | |
| Mar 7, 2024 at 13:59 | comment | added | davidalayachew | But focusing on your solution, using TWR makes it easier because the resource is constrained to a very specific spot. TWR was and is always superior. The problem is, there is no way for me to detect a resource leak. How do I get a compiler error or a compiler warning if I forget to use TWR? That, for me, led me to try and make this monstrosity. However ugly my solution is, you cannot forget to close the resource. And it doesn't serve out dead streams like answers to my other question did -- stackoverflow.com/questions/77959436 | |
| Mar 7, 2024 at 13:57 | comment | added | davidalayachew | You are absolutely right that neither try nor exception handling are bugs. I certainly don't see them that way. And I also understand if the answers I receive will align under "Use the tools that were meant to handle this problem". And since opening a connection to check for parallelism is as bad as you say, that may be enough to require a complete redesign of my approach. But just to give some context. I do some coding on my offtime, and I help a bunch of entry level (and below) devs to build a project. In preparation for upcoming work, I build this because TWR keeps getting forgotten. | |
| Mar 7, 2024 at 13:30 | history | answered | Reinderien | CC BY-SA 4.0 |