• 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
92 (0.07/day)
Likes
9
#1
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
9,125 (2.29/day)
Likes
8,214
System Name Pioneer
Processor Intel i7 8700k @ 4.8 GHz All-Core + Uncore & AVX Offset @ 0
Motherboard ASRock Z370 Taichi
Cooling Noctua NH-U14S + A whole lotta Sunon and Corsair Maglev blower fans...
Memory G.SKILL TridentZ Series 32GB (4 x 8GB) DDR4-3200 @ 14-14-14-34-2T
Video Card(s) NVIDIA Titan XP Star Wars Collectors Edition (Galactic Empire)
Storage HGST UltraStar 7K6000 3.5" HDD 2TB 7200 RPM (w/128MBs of Cache)
Display(s) BenQ BL3200PT (a 1440p VA Panel with decent latency)
Case Thermaltake Core X31
Audio Device(s) Onboard Toslink to Schiit Modi Multibit to Asgard 2 Amp to AKG K7XX Ruby Red Massdrop Headphones
Power Supply Seasonic PRIME 750W 80Plus Titanium
Mouse ROCCAT Kone EMP
Keyboard WASD CODE 104-Key w/ Cherry MX Green Keyswitches, Doubleshot Vortex PBT White Keycaps, Blue legends
Software Windows 10 Enterprise (From former workplace, yay no telemetry)
Benchmark Scores FSExt/TS: FSExt 14625:https://www.3dmark.com/fs/15253894 TS 10496:https://www.3dmark.com/spy/3557134
#2
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,035 (0.44/day)
Likes
558
Location
Arcadia
System Name Xeon build /Main Rig
Processor Intel Xeon w3520 @ 4Ghz with HT /i7 4820k @4.5 Ghz previos 4.6 (too much voltage for 100mhz)
Motherboard Asus P6T Deluxe v2 socket 1366 / Asus P9X79 socket 2011
Cooling Thermalright Archon +Ty 140mm|Fans : 2 front-1top-1rear-1bottom/ Swiftech H140x
Memory 16gb DDR3 1600mhz Kingstone Hyper x Quad Channel / 16gb DDR3 2133MHZ Gskill RipjawsZ
Video Card(s) Sapphire hd 7950 3gb Boost edition dual fan X / XFX R9 Fury X
Storage Kingstone AV400ssd 120gb + Seagate B 2Tb + WD green 1tb + WD green 3tb + WD red 3tb + Seagate B 4tb
Display(s) Wasabi Mango UHD430 43" 4K @60hz with Freesync
Case Fractal Design Arc midi
Audio Device(s) SoundMaxHD+5.1 BHT1100 BLUESKY,Corsair Vengeance 1500 v2,Fiio E10 Olympus+SuperluxHD668b
Power Supply Thermaltake toughpower xt 775watt modular
Mouse Corsair M90
Keyboard Microsoft WK600
Software Windows 7 Ultimate 64bit
#3
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
25,093 (5.43/day)
Likes
11,368
Location
Indiana, USA
Processor Intel Core i7 8700K@4.8GHz(Quick and dirty)
Motherboard AsRock Z370 Taichi
Cooling Corsair H110i GTX w/ Noctua NF-A14 Fans
Memory 32GB Corsair DDR4-3000
Video Card(s) ASUS Strix GTX 1080Ti
Storage 500GB Crucial MX500 + 2TB Seagate Solid State Hybrid Drive with 480GB MX200 SSD Cache
Display(s) QNIX QX2710 1440p@120Hz
Case Fractal Design Define S
Audio Device(s) Onboard is good enough for me
Power Supply Corsair HX850
Software Windows 10 Pro x64
#4
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
22,057 (6.19/day)
Likes
11,117
Location
IA, USA
System Name BY-2015
Processor Intel Core i7-6700K (4 x 4.00 GHz) w/ HT and Turbo on
Motherboard MSI Z170A GAMING M7
Cooling Scythe Kotetsu
Memory 2 x Kingston HyperX DDR4-2133 8 GiB
Video Card(s) PowerColor PCS+ 390 8 GiB DVI + HDMI
Storage Crucial MX300 275 GB, Seagate 6 TB 7200 RPM
Display(s) Samsung SyncMaster T240 24" LCD (1920x1200 HDMI) + Samsung SyncMaster 906BW 19" LCD (1440x900 DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay
Audio Device(s) Realtek Onboard, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse SteelSeries Sensei RAW
Keyboard Tesoro Excalibur
Software Windows 10 Pro 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
Joined
Jan 13, 2015
Messages
92 (0.07/day)
Likes
9
#6
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
163 (0.22/day)
Likes
71
System Name Gaming System
Processor i7-4960X
Motherboard ASUS Rampage IV Black Edition
Cooling Noctua NH-D15
Memory Corsair Vengeance LP 32GB DDR3
Video Card(s) EVGA GTX 1080 ti FTW3
Storage 1TB Samsung 850 EVO; 500GB Samsung 850 EVO
Display(s) HP zr2740w Surround
Case Corsair A540
Audio Device(s) onboard
Power Supply EVGA G2 1300
Mouse Logitech MK550
Keyboard Logitech MK550
Software Windows 10 Pro
#7
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
10,729 (4.54/day)
Likes
5,847
Location
Concord, NH
System Name Kratos
Processor Intel Core i7 3930k @ 4.5Ghz
Motherboard ASUS P9X79 Deluxe
Cooling Corsair H100i V2
Memory G.Skill DDR3-2133, 16gb (4x4gb) @ 9-11-10-28-108-1T 1.65v
Video Card(s) MSI AMD Radeon R9 390 GAMING 8GB @ PCI-E 3.0
Storage 2x120Gb SATA3 Corsair Force GT Raid-0, 4x1Tb RAID-5, 1x500GB
Display(s) 1x LG 27UD69P (4k), 2x Dell S2340M (1080p)
Case Antec 1200
Audio Device(s) Onboard Realtek® ALC898 8-Channel High Definition Audio
Power Supply Seasonic 1000-watt 80 PLUS Platinum
Mouse Logitech G602
Keyboard Rosewill RK-9100
Software Ubuntu 18.04
Benchmark Scores Benchmarks aren't everything.
#8
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
92 (0.07/day)
Likes
9
#9
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
10,729 (4.54/day)
Likes
5,847
Location
Concord, NH
System Name Kratos
Processor Intel Core i7 3930k @ 4.5Ghz
Motherboard ASUS P9X79 Deluxe
Cooling Corsair H100i V2
Memory G.Skill DDR3-2133, 16gb (4x4gb) @ 9-11-10-28-108-1T 1.65v
Video Card(s) MSI AMD Radeon R9 390 GAMING 8GB @ PCI-E 3.0
Storage 2x120Gb SATA3 Corsair Force GT Raid-0, 4x1Tb RAID-5, 1x500GB
Display(s) 1x LG 27UD69P (4k), 2x Dell S2340M (1080p)
Case Antec 1200
Audio Device(s) Onboard Realtek® ALC898 8-Channel High Definition Audio
Power Supply Seasonic 1000-watt 80 PLUS Platinum
Mouse Logitech G602
Keyboard Rosewill RK-9100
Software Ubuntu 18.04
Benchmark Scores Benchmarks aren't everything.
#10
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.

No one uses applets anymore. :)
 
Last edited:
Joined
Jan 13, 2015
Messages
92 (0.07/day)
Likes
9
#11
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
22,057 (6.19/day)
Likes
11,117
Location
IA, USA
System Name BY-2015
Processor Intel Core i7-6700K (4 x 4.00 GHz) w/ HT and Turbo on
Motherboard MSI Z170A GAMING M7
Cooling Scythe Kotetsu
Memory 2 x Kingston HyperX DDR4-2133 8 GiB
Video Card(s) PowerColor PCS+ 390 8 GiB DVI + HDMI
Storage Crucial MX300 275 GB, Seagate 6 TB 7200 RPM
Display(s) Samsung SyncMaster T240 24" LCD (1920x1200 HDMI) + Samsung SyncMaster 906BW 19" LCD (1440x900 DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay
Audio Device(s) Realtek Onboard, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse SteelSeries Sensei RAW
Keyboard Tesoro Excalibur
Software Windows 10 Pro 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
#12
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
10,729 (4.54/day)
Likes
5,847
Location
Concord, NH
System Name Kratos
Processor Intel Core i7 3930k @ 4.5Ghz
Motherboard ASUS P9X79 Deluxe
Cooling Corsair H100i V2
Memory G.Skill DDR3-2133, 16gb (4x4gb) @ 9-11-10-28-108-1T 1.65v
Video Card(s) MSI AMD Radeon R9 390 GAMING 8GB @ PCI-E 3.0
Storage 2x120Gb SATA3 Corsair Force GT Raid-0, 4x1Tb RAID-5, 1x500GB
Display(s) 1x LG 27UD69P (4k), 2x Dell S2340M (1080p)
Case Antec 1200
Audio Device(s) Onboard Realtek® ALC898 8-Channel High Definition Audio
Power Supply Seasonic 1000-watt 80 PLUS Platinum
Mouse Logitech G602
Keyboard Rosewill RK-9100
Software Ubuntu 18.04
Benchmark Scores Benchmarks aren't everything.
#13
Joined
Aug 20, 2007
Messages
9,125 (2.29/day)
Likes
8,214
System Name Pioneer
Processor Intel i7 8700k @ 4.8 GHz All-Core + Uncore & AVX Offset @ 0
Motherboard ASRock Z370 Taichi
Cooling Noctua NH-U14S + A whole lotta Sunon and Corsair Maglev blower fans...
Memory G.SKILL TridentZ Series 32GB (4 x 8GB) DDR4-3200 @ 14-14-14-34-2T
Video Card(s) NVIDIA Titan XP Star Wars Collectors Edition (Galactic Empire)
Storage HGST UltraStar 7K6000 3.5" HDD 2TB 7200 RPM (w/128MBs of Cache)
Display(s) BenQ BL3200PT (a 1440p VA Panel with decent latency)
Case Thermaltake Core X31
Audio Device(s) Onboard Toslink to Schiit Modi Multibit to Asgard 2 Amp to AKG K7XX Ruby Red Massdrop Headphones
Power Supply Seasonic PRIME 750W 80Plus Titanium
Mouse ROCCAT Kone EMP
Keyboard WASD CODE 104-Key w/ Cherry MX Green Keyswitches, Doubleshot Vortex PBT White Keycaps, Blue legends
Software Windows 10 Enterprise (From former workplace, yay no telemetry)
Benchmark Scores FSExt/TS: FSExt 14625:https://www.3dmark.com/fs/15253894 TS 10496:https://www.3dmark.com/spy/3557134
#14
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
10,729 (4.54/day)
Likes
5,847
Location
Concord, NH
System Name Kratos
Processor Intel Core i7 3930k @ 4.5Ghz
Motherboard ASUS P9X79 Deluxe
Cooling Corsair H100i V2
Memory G.Skill DDR3-2133, 16gb (4x4gb) @ 9-11-10-28-108-1T 1.65v
Video Card(s) MSI AMD Radeon R9 390 GAMING 8GB @ PCI-E 3.0
Storage 2x120Gb SATA3 Corsair Force GT Raid-0, 4x1Tb RAID-5, 1x500GB
Display(s) 1x LG 27UD69P (4k), 2x Dell S2340M (1080p)
Case Antec 1200
Audio Device(s) Onboard Realtek® ALC898 8-Channel High Definition Audio
Power Supply Seasonic 1000-watt 80 PLUS Platinum
Mouse Logitech G602
Keyboard Rosewill RK-9100
Software Ubuntu 18.04
Benchmark Scores Benchmarks aren't everything.
#15
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
92 (0.07/day)
Likes
9
#16
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
92 (0.07/day)
Likes
9
#17
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
9,125 (2.29/day)
Likes
8,214
System Name Pioneer
Processor Intel i7 8700k @ 4.8 GHz All-Core + Uncore & AVX Offset @ 0
Motherboard ASRock Z370 Taichi
Cooling Noctua NH-U14S + A whole lotta Sunon and Corsair Maglev blower fans...
Memory G.SKILL TridentZ Series 32GB (4 x 8GB) DDR4-3200 @ 14-14-14-34-2T
Video Card(s) NVIDIA Titan XP Star Wars Collectors Edition (Galactic Empire)
Storage HGST UltraStar 7K6000 3.5" HDD 2TB 7200 RPM (w/128MBs of Cache)
Display(s) BenQ BL3200PT (a 1440p VA Panel with decent latency)
Case Thermaltake Core X31
Audio Device(s) Onboard Toslink to Schiit Modi Multibit to Asgard 2 Amp to AKG K7XX Ruby Red Massdrop Headphones
Power Supply Seasonic PRIME 750W 80Plus Titanium
Mouse ROCCAT Kone EMP
Keyboard WASD CODE 104-Key w/ Cherry MX Green Keyswitches, Doubleshot Vortex PBT White Keycaps, Blue legends
Software Windows 10 Enterprise (From former workplace, yay no telemetry)
Benchmark Scores FSExt/TS: FSExt 14625:https://www.3dmark.com/fs/15253894 TS 10496:https://www.3dmark.com/spy/3557134
#18
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
10,729 (4.54/day)
Likes
5,847
Location
Concord, NH
System Name Kratos
Processor Intel Core i7 3930k @ 4.5Ghz
Motherboard ASUS P9X79 Deluxe
Cooling Corsair H100i V2
Memory G.Skill DDR3-2133, 16gb (4x4gb) @ 9-11-10-28-108-1T 1.65v
Video Card(s) MSI AMD Radeon R9 390 GAMING 8GB @ PCI-E 3.0
Storage 2x120Gb SATA3 Corsair Force GT Raid-0, 4x1Tb RAID-5, 1x500GB
Display(s) 1x LG 27UD69P (4k), 2x Dell S2340M (1080p)
Case Antec 1200
Audio Device(s) Onboard Realtek® ALC898 8-Channel High Definition Audio
Power Supply Seasonic 1000-watt 80 PLUS Platinum
Mouse Logitech G602
Keyboard Rosewill RK-9100
Software Ubuntu 18.04
Benchmark Scores Benchmarks aren't everything.
#19
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
92 (0.07/day)
Likes
9
#20
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
10,047 (2.17/day)
Likes
2,416
System Name MoFo 2
Processor AMD PhenomII 1100T @ 4.2Ghz
Motherboard Asus Crosshair IV
Cooling Swiftec 655 pump, Apogee GT,, MCR360mm Rad, 1/2 loop.
Memory 8GB DDR3-2133 @ 1900 8.9.9.24 1T
Video Card(s) HD7970 1250/1750
Storage Agility 3 SSD 6TB RAID 0 on RAID Card
Display(s) 46" 1080P Toshiba LCD
Case Rosewill R6A34-BK modded (thanks to MKmods)
Audio Device(s) ATI HDMI
Power Supply 750W PC Power & Cooling modded (thanks to MKmods)
Software A lot.
Benchmark Scores Its fast. Enough.
#21
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
92 (0.07/day)
Likes
9
#22
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
22,139 (5.49/day)
Likes
6,623
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

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
22,057 (6.19/day)
Likes
11,117
Location
IA, USA
System Name BY-2015
Processor Intel Core i7-6700K (4 x 4.00 GHz) w/ HT and Turbo on
Motherboard MSI Z170A GAMING M7
Cooling Scythe Kotetsu
Memory 2 x Kingston HyperX DDR4-2133 8 GiB
Video Card(s) PowerColor PCS+ 390 8 GiB DVI + HDMI
Storage Crucial MX300 275 GB, Seagate 6 TB 7200 RPM
Display(s) Samsung SyncMaster T240 24" LCD (1920x1200 HDMI) + Samsung SyncMaster 906BW 19" LCD (1440x900 DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay
Audio Device(s) Realtek Onboard, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse SteelSeries Sensei RAW
Keyboard Tesoro Excalibur
Software Windows 10 Pro 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
#24
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
7,657 (2.53/day)
Likes
4,238
Location
Rochester area
System Name Kreij Lives On
Processor Intel Core i5 4670K @ 4.4Ghz 1.32V
Motherboard ASUS Maximus VI Gene Z87
Cooling Reeven Okeanos Single 140MM Fan +2 SP120 White's
Memory 16GB kingston hyper x @ 2133 @ 11 11 11 32
Video Card(s) EVGA GTX 1060 ACX Copper Single fan
Storage 240gb Cruical MX200SSD/WD Blue 1TB
Display(s) Samsung S24D300/HP2071D
Case Custom Full Aluminum By ST.o.CH <3
Audio Device(s) onboard
Power Supply HX 750i
Mouse Roccat KONE
Keyboard Rocatt ISKU with ISKUFX keycaps
Software Windows 10 +startisback
#25
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