Aquinus
Resident Wat-man
- Joined
- Jan 28, 2012
- Messages
- 13,173 (2.78/day)
- Location
- Concord, NH, USA
System Name | Apollo |
---|---|
Processor | Intel Core i9 9880H |
Motherboard | Some proprietary Apple thing. |
Memory | 64GB DDR4-2667 |
Video Card(s) | AMD Radeon Pro 5600M, 8GB HBM2 |
Storage | 1TB Apple NVMe, 4TB External |
Display(s) | Laptop @ 3072x1920 + 2x LG 5k Ultrafine TB3 displays |
Case | MacBook Pro (16", 2019) |
Audio Device(s) | AirPods Pro, Sennheiser HD 380s w/ FIIO Alpen 2, or Logitech 2.1 Speakers |
Power Supply | 96w Power Adapter |
Mouse | Logitech MX Master 3 |
Keyboard | Logitech G915, GL Clicky |
Software | MacOS 12.1 |
The correct way to do this in Java to maximize concurrency would be to use a stream IMHO.If you're not looking for that major of a change, you could consider changing your array lists to arrays. Array lists have a huge performance penalty when they have to expand their internal arrays.
While your comment is colorful, it's not true or helpful. Java has performance similar to other JIT languages like C# and tends to be eclipsed only by languages like C and C++ which isn't a low bar. I'll concede that the JVM tends to consume a lot of memory but, that's more because if you give it more heap space, it will use it (kind of how the OS will do disk caching with free memory. It's there, so why not use it?) There are plenty of applications that can still run even if you reduce the max size of the heap as well. The JVM is also more than capable of using multiple hardware threads.expecting efficient cpu usage from java is sorta like expecting a 300lb man not to use the handicap electric carts at the store
its possible but extremely unlikely and generally a inconvenience for all
That's probably not the best way to go about it. The best way to handle mutable state with multiple threads is .wait and .notify. Join is appropriate if you're waiting for thread termination to indicate that processing is done but, spinning up threads is a relatively expensive task and you don't want to be spawning a thread every time you need to render a frame. I suggest using a stream because it decouples the consumer from the producer and doesn't require spinning up new threads often. It also opens the possibility of having multiple workers on either the producer or consumer side which could further improve performance depending on where the bottleneck is and if you can just throw more threads at the problem (OpenGL calls won't benefit from this.) Interrupt isn't a good option because you're basically telling the thread to halt execution, even if the task isn't yet complete. If you're not getting an InterruptedException, then the thread already has likely finished executing by the time .interrupt has been invoked otherwise something might not be completing every time.Essentially I made use of the "interrupt" and "join" methods inherited from the Thread class.