• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Possible to force my java app to use more CPU utilization?

Joined
Jan 13, 2015
Messages
135 (0.04/day)
Hey folks,

I've been developing a Java applet that requires significant CPU utilization. For the moment, I'm only able to run it from the IDE, Java NetBeans. I've been having issues getting it to work on a web browser due to security issues. Nevertheless, when I run the app, I noticed that the Task Manager shows about 20% CPU utilization. Is this a limitation of the OS (Windows 10, 64-bit)? I'd like for it to utilize at least 70% of the CPU'S capability, if not more. Is there a way to force my app to utilize the CPU to that extent?

The laptop PC's I've been running the app on have Intel CPU's (i7-4720HQ, 3610QM) with 24GB and 32 GB of RAM respectively. They both have the latest Java JDK/JRE installed.

Any and all advice is greatly appreciated.

Cheers.
 
Joined
Aug 20, 2007
Messages
20,758 (3.41/day)
System Name Pioneer
Processor Ryzen R9 7950X
Motherboard GIGABYTE Aorus Elite X670 AX
Cooling Noctua NH-D15 + A whole lotta Sunon and Corsair Maglev blower fans...
Memory 64GB (4x 16GB) G.Skill Flare X5 @ DDR5-6000 CL30
Video Card(s) XFX RX 7900 XTX Speedster Merc 310
Storage 2x Crucial P5 Plus 2TB PCIe 4.0 NVMe SSDs
Display(s) 55" LG 55" B9 OLED 4K Display
Case Thermaltake Core X31
Audio Device(s) TOSLINK->Schiit Modi MB->Asgard 2 DAC Amp->AKG Pro K712 Headphones or HDMI->B9 OLED
Power Supply FSP Hydro Ti Pro 850W
Mouse Logitech G305 Lightspeed Wireless
Keyboard WASD Code v3 with Cherry Green keyswitches + PBT DS keycaps
Software Gentoo Linux x64
You are probably using all of one core of a quad core. You'll need to multithread your app to get more performance. This is not necessarily easy.
 
Joined
Jan 15, 2012
Messages
1,194 (0.27/day)
Location
Arcadia
System Name Xeon build X58 / Main Rig X79
Processor Intel Xeon x5650 @ 4.2Ghz with HT / Xeon E5 1650 v2 @4.5Ghz
Motherboard Asus Rampage II Extreme socket 1366 / Asus P9X79 Pro socket 2011
Cooling Thermalright Archon +Ty 140mm|Fans : 2 front-1top-1rear-1bottom/ Gelid Phantom Twin Tower
Memory 16gb DDR3 1600mhz Kingstone Hyper x Quad Channel / 16gb DDR3 1600MHZ Patriot Viper 3
Video Card(s) Sapphire hd 7950 3gb Boost edition dual fan X / ZOTAC 1080 Ti Blower Edition
Storage Kingstone AV400ssd 120gb+Seagate B 2Tb+WD g 1tb+WD g 3tb+WD r 3tb+Seagate B 4tb+Lexar 2Tb NVMe
Display(s) AOC E2460S 24" 1080p 60hz 1ms / LG 32UK550B 32" UHD 4K HDR 10 with Freesync
Case Enermax Phoenix / Fractal Design Arc midi
Audio Device(s) SoundMaxHD+5.1 BHT1100 BLUESKY,Fiio E10 Olympus+SuperluxHD668b+KZ HBB pr2,Superlux E205.
Power Supply Sharkoon WPM Gold Zero 650W semi modular / Corsair RM 850 Fully Modular
Mouse Generic Mice / Corsair M90
Keyboard Generic Keyboard / Microsoft WK600
Software Windows 10 Pro 64 /Windows 10 Pro 64
Hi , you can try to set the cpu priorities to real time and set the affinity too and lower the ones of other applications.

Edit: inside taskmanager.
 
Last edited:

newtekie1

Semi-Retired Folder
Joined
Nov 22, 2005
Messages
28,472 (4.24/day)
Location
Indiana, USA
Processor Intel Core i7 10850K@5.2GHz
Motherboard AsRock Z470 Taichi
Cooling Corsair H115i Pro w/ Noctua NF-A14 Fans
Memory 32GB DDR4-3600
Video Card(s) RTX 2070 Super
Storage 500GB SX8200 Pro + 8TB with 1TB SSD Cache
Display(s) Acer Nitro VG280K 4K 28"
Case Fractal Design Define S
Audio Device(s) Onboard is good enough for me
Power Supply eVGA SuperNOVA 1000w G3
Software Windows 10 Pro x64
I don't even thinkg Java apps can be multi-threaded. If they could, I'd think programs like Minecraft would have done it long ago, but they haven't.
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.64/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
Joined
Jan 13, 2015
Messages
135 (0.04/day)
Thanks for the quick responses.

Captain Harlock: I was able to modify the CPU priorities and affinity. But there wasn't any change in the CPU utilization.

Ford: Thanks for the link, there's a lot of information in that article, but at first glance, I don't think it said anything with respect to CPU utilization across all cores.

I was hoping that there would be a compiler directive that enables the use of all cores on the CPU. I've already enabled the directive to compile the code to 64-bit mode (for lack of better terminology).

Any other ideas?
 
Joined
Jul 9, 2016
Messages
1,068 (0.38/day)
System Name Main System
Processor i9-10940x
Motherboard MSI X299 Xpower Gaming AC
Cooling Noctua NH-D15S + Second Fan
Memory G.Skill 64GB @3200MHz XMP
Video Card(s) ASUS Strix RTX 3090 24GB
Storage 2TB Samsung 970 EVO Plus; 2TB Corsair Force MP600; 2TB Samsung PM981a
Display(s) Dell U4320Q; LG 43MU79-B
Case Corsair A540
Audio Device(s) Creative Lab SoundBlaster ZX-R
Power Supply EVGA G2 1300
Mouse Logitech MK550
Keyboard Corsair K95 Platinum XT Brown Switches
Software Windows 10 Pro
Benchmark Scores Cinebench R20 - 6910; FireStrike Ultra - 13241; TimeSpy Extreme - 10067; Port Royal - 13855
There is no single compiler directive or library that can instantly turn your app into multi-threaded, because that would be too easy ;)

Are you making a Java application (jar)? To make any multi-threaded application, you really need to think carefully and structure your code so that the compiler/runtime knows certain sections of code or method calls can be done asynchronously, in C# such as Task or async. Otherwise, the runtime will not know where to hand off computation to a different thread. Of course, with modern compilers there will be built in improvement to speed up certain tasks using multiple threads, but to make your code a multi-threaded app, you will need to do it yourself.

Most applications are fine running single thread, such as Word or Powerpoint. Multi-threaded apps are suited for computation intensive apps such as scientific or gaming. Few apps need that hence developers general don't spend time doing it, as the task is not easy. That is also why you see some games are poorly optimized to run on multi-core processors. What app are you making require so much computation?
 

Aquinus

Resident Wat-man
Joined
Jan 28, 2012
Messages
13,147 (2.95/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
Java doesn't just automatically make your code run concurrently. You need to tell Java that and you need to do extra work to make sure that it remains thread safe and a lot of times, people who don't know what they're doing, won't see any performance benefit because you can't just throw more threads and more cores at a problem and expect everything to work out. I personally don't really write Java very often anymore but, I do write a lot of Clojure which runs on top of the JVM and I can say that it's very capable of utilizing a quad-core CPU.

Whenever you decide to make an application multi-threaded, there are a lot of questions you need to be asking yourself because there is always a trade-off with using additional threads.

So, if you want us to help you think through what parts of your application can be made to be concurrent and yield the most likely case of improving performance, then you need to tell us a bit about the problem you're trying to solve, otherwise this thread ends right here because as someone who writes multi-threaded code that runs on the JVM, I can't help if I don't know what the task is.
 
Joined
Jan 13, 2015
Messages
135 (0.04/day)
I've been away from Java for a while, so my code is not the most efficient. Nevertheless, like I stated in my first post, It's a Java Applet. The purpose is to make interesting linear designs through animating individual points. I put it in an infinite update/repaint loop, as per the conventional method to make applets animate and execute code to handle updates with each iteration. I suppose you could say that is the primary thread. Every loop, it recalculates the new position of the individual points, and draws them to an image buffer. I use double buffering to make the animation appear smooth. The other half of the app is the UI. I used Netbeans to create the UI (a JFrame) that the applet instantiates. The applet has a timer that executes code every 10 ms. Every 10 ms, the applet checks the UI for state changes in the UI controls and performs the appropriate action. It has a bunch of Jbuttons, Jsliders, Jlist boxes, etc.

That chunk of code looks like this:

Timer timer = new Timer(10, new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
//User input handling goes here...
}
});
timer.setRepeats(true);
timer.start();

I used a Timer because it was the simplest to implement. There's likely a better way to do this, but it works just as I had envisioned. Lastly, the meat of the code is in calculating the position and colors of the individual pixels. I'm using a lot of mathematical functions like sin, cos, etc. This is where most of the CPU spends it's time calculating. That's pretty much it. Simple in design. My objective, for the moment, is to get this app to utilize the CPU to the extent of it's capability. I don't care if that means multi-threading or code optimization. I guess you can say, whatever works without mangling the code...
 

Aquinus

Resident Wat-man
Joined
Jan 28, 2012
Messages
13,147 (2.95/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
I guess you can say, whatever works without mangling the code.
Then stop right now because you'll need to mangle that calculation of pixel colors and positions to multi-thread it in a useful way, assuming it's not a calculation that also has some sort of effect. There is no switch to use the rest of your CPU. :p

In all seriousness, you should use a queue in front of and after the calculations with sin, cos, etc. so you can scale the number of workers doing strict math to the resources available on the machine being used. Since these workers are merely processing data (which means, no side-effects,) then the threads can merely stick around and you just feed a queue and pull from the queue (you could even use a thread pool.) Just keep in mind there is coordination overhead that needs to be factored in and you can't do this by not changing your code, probably significantly.

Java Applet
No one uses applets anymore. :)
 
Last edited:
Joined
Jan 13, 2015
Messages
135 (0.04/day)
Then stop right now because you'll need to mangle that calculation of pixel colors and positions to multi-thread it in a useful way, assuming it's not a calculation that also has some sort of effect. There is no switch to use the rest of your CPU. :p

Yea, I think the added complexity isn't worth improvement in performance.

No one uses applets anymore. :)

I'm considering porting the applet code to a standard Java app. As I've mentioned in the first post, the primary reason I wanted to create an applet was to be able to have it run in a web browser. Unfortunately, I'm finding it more and more difficult to get it to work due to security issues. Does animation work just as well with a JFrame? If so, what combination of Swing Containers/Controls/Windows works best?
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.64/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
Since your focus is web, perhaps you should look into HTML5 animation instead:
http://www.html5canvastutorials.com/advanced/html5-canvas-animation-stage/

Pretty sure browsers run animations in the GPU so you're killing two birds with one stone (no more security issues and should vastly improve draw performance).


If you demand to stick to Java, is each frame static? Do you know the inputs and outputs of frame 2 and 3 while working on frame 1? If yes and yes, you could create a function which draws each frame given the frame number and have the number of processors minus one (for main thread) drawing a frame. Have the main thread pull from the queue of finished frames at a regular interval and order the thread that it took the frame from to work on the next frame in the queue. In a quad core processor (three workers), for example, it would wait for frame 1 from worker 1 then worker would start on frame 4 while the main thread draws frame 2 from worker 2 (so on and so fourth).
 
Last edited:

Aquinus

Resident Wat-man
Joined
Jan 28, 2012
Messages
13,147 (2.95/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
Joined
Aug 20, 2007
Messages
20,758 (3.41/day)
System Name Pioneer
Processor Ryzen R9 7950X
Motherboard GIGABYTE Aorus Elite X670 AX
Cooling Noctua NH-D15 + A whole lotta Sunon and Corsair Maglev blower fans...
Memory 64GB (4x 16GB) G.Skill Flare X5 @ DDR5-6000 CL30
Video Card(s) XFX RX 7900 XTX Speedster Merc 310
Storage 2x Crucial P5 Plus 2TB PCIe 4.0 NVMe SSDs
Display(s) 55" LG 55" B9 OLED 4K Display
Case Thermaltake Core X31
Audio Device(s) TOSLINK->Schiit Modi MB->Asgard 2 DAC Amp->AKG Pro K712 Headphones or HDMI->B9 OLED
Power Supply FSP Hydro Ti Pro 850W
Mouse Logitech G305 Lightspeed Wireless
Keyboard WASD Code v3 with Cherry Green keyswitches + PBT DS keycaps
Software Gentoo Linux x64
I don't even thinkg Java apps can be multi-threaded. If they could, I'd think programs like Minecraft would have done it long ago, but they haven't.

Ironically, Java is one of the most multithreading friendly languages around. Minecraft is just a coders nightmare.
 

Aquinus

Resident Wat-man
Joined
Jan 28, 2012
Messages
13,147 (2.95/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
Ironically, Java is one of the most multithreading friendly languages around. Minecraft is just a coders nightmare.
This in the sense that it has some of the best facilities for doing it but, I wouldn't call it easy in the sense that locking is the only way to handle controlled mutation of a thread-safe reference. Clojure, being a functional lisp on that runs on the JVM makes multi-threading a piece of cake and it uses the JVM for that reason. A dynamic language that runs on the JVM and can run almost as fast as native java, is freaking awesome. I use it and evangelize it for a reason.

https://benchmarksgame.alioth.debian.org/u64q/clojure.html
Disclaimer: The benchmark game is both a benchmark and a game.

I'm not fanatical about many things but, Clojure is one of them.
 
Joined
Jan 13, 2015
Messages
135 (0.04/day)
Since your focus is web, perhaps you should look into HTML5 animation instead:
http://www.html5canvastutorials.com/advanced/html5-canvas-animation-stage/

Pretty sure browsers run animations in the GPU so you're killing two birds with one stone (no more security issues and should vastly improve draw performance).

This looks interesting. How does this compare to Java in terms of speed?

If you demand to stick to Java, is each frame static? Do you know the inputs and outputs of frame 2 and 3 while working on frame 1? If yes and yes, you could create a function which draws each frame given the frame number and have the number of processors minus one (for main thread) drawing a frame. Have the main thread pull from the queue of finished frames at a regular interval and order the thread that it took the frame from to work on the next frame in the queue. In a quad core processor (three workers), for example, it would wait for frame 1 from worker 1 then worker would start on frame 4 while the main thread draws frame 2 from worker 2 (so on and so fourth).

My main class is a stand-alone applet that instantiates a Jframe for user controls. I can access the properties and controls this way. Ideally, I'd like to create another Jframe as a "drawing canvas" where the animation will take place. I've yet to figure this out. I'm assuming the drawing canvas will require a Swing JPanel and perhaps a JLabel. My best guess is that I will need to update the JLabel with the graphics I wish to display/animate.
 
Joined
Jan 13, 2015
Messages
135 (0.04/day)
Well... I decided to port My applet to a Java App. I took the 1% inspiration, 99% perspiration approach. After a significant amount of research, I was able to do it. No mangling of the code, just well thought out adjustments. So now, I can run the app from the command-line, whereas before, I was bound to the IDE. Cool stuff. In terms of speed improvement, initial tests show about the same. Perhaps 1 or 2 fps better, but not much more.

Here are some other observations. When I run my app, it uses about 20% CPU utilization. When I spawn a second or third instance of the app, each instance also uses about 20% CPU utilization. Since java is multi platform compatible, I'm wondering how it will perform on Linux. Will it use the CPU to its full extent? Or will it perform exactly the same as in Windows 10? Do any of you guys have experience with this regard?
 
Joined
Aug 20, 2007
Messages
20,758 (3.41/day)
System Name Pioneer
Processor Ryzen R9 7950X
Motherboard GIGABYTE Aorus Elite X670 AX
Cooling Noctua NH-D15 + A whole lotta Sunon and Corsair Maglev blower fans...
Memory 64GB (4x 16GB) G.Skill Flare X5 @ DDR5-6000 CL30
Video Card(s) XFX RX 7900 XTX Speedster Merc 310
Storage 2x Crucial P5 Plus 2TB PCIe 4.0 NVMe SSDs
Display(s) 55" LG 55" B9 OLED 4K Display
Case Thermaltake Core X31
Audio Device(s) TOSLINK->Schiit Modi MB->Asgard 2 DAC Amp->AKG Pro K712 Headphones or HDMI->B9 OLED
Power Supply FSP Hydro Ti Pro 850W
Mouse Logitech G305 Lightspeed Wireless
Keyboard WASD Code v3 with Cherry Green keyswitches + PBT DS keycaps
Software Gentoo Linux x64
Well... I decided to port My applet to a Java App. I took the 1% inspiration, 99% perspiration approach. After a significant amount of research, I was able to do it. No mangling of the code, just well thought out adjustments. So now, I can run the app from the command-line, whereas before, I was bound to the IDE. Cool stuff. In terms of speed improvement, initial tests show about the same. Perhaps 1 or 2 fps better, but not much more.

Here are some other observations. When I run my app, it uses about 20% CPU utilization. When I spawn a second or third instance of the app, each instance also uses about 20% CPU utilization. Since java is multi platform compatible, I'm wondering how it will perform on Linux. Will it use the CPU to its full extent? Or will it perform exactly the same as in Windows 10? Do any of you guys have experience with this regard?

No OS is going to change your single-threaded workload limit.
 

Aquinus

Resident Wat-man
Joined
Jan 28, 2012
Messages
13,147 (2.95/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
Do any of you guys have experience with this regard?
I'm a software engineer that has written multi-threaded code in production systems. I can tell you right now that nothing will use more of your CPU unless you modify it to take advantage of multiple cores and this isn't a task for the inexperienced if you want to do it right because doing it wrong can harm performance. AS @R-T-B said:
No OS is going to change your single-threaded workload limit.
...and that it's on you as the dev to implement these changes if the time is worth the potential improvement. There are also trade-offs to altering a program to be multi-threaded. Usually the best way to achieve this is to decouple the "what" from the "when" by putting queues between each stage of your computation. That allows you to essentially parallize serial workloads. The problem here though is that while bandwidth will increase, latency will increase as well due to conveying values from one part of the application running on one thread to another part running on another. The other way is to take the most parallel part of your application and merely have more threads work on it which is basically the first suggestion plus some extra work to allow a single stage to have more than one worker.

All of these things incur overhead and require dev from a skilled dev with good understanding of computer science concepts to analyze if the cost of implementation is worth the speed up or if it would even result in any speed up at all. If you haven't profiled your application first, then you might want to start there. That would at least indentify which parts of your application are going slow relative to the rest of the application and multi-threading means nothing until you've done that. The world is a very different place when you start having to consider shared memory and multiple concurrent processes which is part of the reason why I use Clojure for most of my day-to-day dev needs that don't need to run somewhere where Clojure (the JVM; Java,) is available. Immutable data is a beautiful thing when it comes to concurrency.

tl;dr: Profile your app first before even considering multi-threading and multi-threading isn't for the faint of heart.
 
Joined
Jan 13, 2015
Messages
135 (0.04/day)
Thanks for the input Aquinus. I think I'm going to leave my app the way it is. If I implemented multi-threading, I might get a marginal improvement. I don't think it's worth the effort. From what I can tell, debugging an app of this sort would be a good recipe for a migraine :banghead:.
 
Joined
Nov 4, 2005
Messages
11,676 (1.73/day)
System Name Compy 386
Processor 7800X3D
Motherboard Asus
Cooling Air for now.....
Memory 64 GB DDR5 6400Mhz
Video Card(s) 7900XTX 310 Merc
Storage Samsung 990 2TB, 2 SP 2TB SSDs and over 10TB spinning
Display(s) 56" Samsung 4K HDR
Audio Device(s) ATI HDMI
Mouse Logitech MX518
Keyboard Razer
Software A lot.
Benchmark Scores Its fast. Enough.
Short answer? No.

Long answer, not without modifying application code for a multithreaded and slower in some scenarios approach.

If performance is really the issue, send if it can be written in something other than Java, as it's dying.

Or get a faster single threaded CPU or overclock.
 
Joined
Jan 13, 2015
Messages
135 (0.04/day)
I had to resurrect this thread because I have taken upon myself to learn multi-threading in Java. I created a double buffered animating app that uses a thread for drawing the images to a JFrame while another thread performs the logic (update calculations). To make a long story short, I was able to increase the CPU usage from 18% to over 33%. This a substantial improvement. Something worth mentioning. The app was designed with Array Lists of objects. The Logic thread updates the objects while the primary thread draws them. The inherent problem with this is that it generates Concurrent Execution errors. So, I had to write clever coding to avoid this. The best solution I was able to devise, was to make clones of the array lists before drawing them. This way the primary thread has a copy of the data that won't be modified until the drawing phase has completed. In the meantime, the logic thread calculates the next iteration. It's not the most efficient technique, but it is certainly effective. The other obstacle was to learn how to terminate the thread. Without properly terminating the threads, your PC can lockup. Essentially I made use of the "interrupt" and "join" methods inherited from the Thread class. I'm not 100% sure why this works, but I did create a destructor to confirm its functionality.

So, in short, multi-threading, without a doubt can improve the performance of your Java App. But you need to do the research as there are many pitfalls. If anyone has questions or comments, feel free to respond.

Cheers,

grecinos
 

eidairaman1

The Exiled Airman
Joined
Jul 2, 2007
Messages
40,435 (6.59/day)
Location
Republic of Texas (True Patriot)
System Name PCGOD
Processor AMD FX 8350@ 5.0GHz
Motherboard Asus TUF 990FX Sabertooth R2 2901 Bios
Cooling Scythe Ashura, 2×BitFenix 230mm Spectre Pro LED (Blue,Green), 2x BitFenix 140mm Spectre Pro LED
Memory 16 GB Gskill Ripjaws X 2133 (2400 OC, 10-10-12-20-20, 1T, 1.65V)
Video Card(s) AMD Radeon 290 Sapphire Vapor-X
Storage Samsung 840 Pro 256GB, WD Velociraptor 1TB
Display(s) NEC Multisync LCD 1700V (Display Port Adapter)
Case AeroCool Xpredator Evil Blue Edition
Audio Device(s) Creative Labs Sound Blaster ZxR
Power Supply Seasonic 1250 XM2 Series (XP3)
Mouse Roccat Kone XTD
Keyboard Roccat Ryos MK Pro
Software Windows 7 Pro 64
You could always peruse oracle or whoever owns java and their forums. @FordGT90Concept, know anything about OOP?
 

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.64/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
This is still better done on GPU via HTML5:
https://www.html5canvastutorials.com/advanced/html5-canvas-animation-stage/

In Java, you should be creating a OpenGL render context and do your drawing in there (via GPU). CPU should spend its time figuring out what to draw, not actually draw it.


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.
 
Last edited:

OneMoar

There is Always Moar
Joined
Apr 9, 2010
Messages
8,744 (1.71/day)
Location
Rochester area
System Name RPC MK2.5
Processor Ryzen 5800x
Motherboard Gigabyte Aorus Pro V2
Cooling Enermax ETX-T50RGB
Memory CL16 BL2K16G36C16U4RL 3600 1:1 micron e-die
Video Card(s) GIGABYTE RTX 3070 Ti GAMING OC
Storage ADATA SX8200PRO NVME 512GB, Intel 545s 500GBSSD, ADATA SU800 SSD, 3TB Spinner
Display(s) LG Ultra Gear 32 1440p 165hz Dell 1440p 75hz
Case Phanteks P300 /w 300A front panel conversion
Audio Device(s) onboard
Power Supply SeaSonic Focus+ Platinum 750W
Mouse Kone burst Pro
Keyboard EVGA Z15
Software Windows 11 +startisallback
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
 
Top