Přeskočit na hlavní obsah

Příspěvky

Zobrazují se příspěvky z srpen, 2013

Have you met Thread?

I’m pretty sure, you know java.lang.Thread class and it’s API. Today I want to spend some time with sleep method.   void sleep (long millis) is pretty straight – just remember not to set negative value and be ready for InterruptedException , that’s it. But what if you need better precision? Great, there is another sleep method, this time with two arguments – millis and nanos. The Javadoc is clear: Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers. See? You can set some amount of nanoseconds to the Thread to sleep, but the precision is dictated by system timers and schedulers.  Okay computers are fast these days, so the precision wouldn’t be so bad. You start to use it, but the results are far from what you expected. Double check your code, everything looks good. Okay it is time to see the source code. WTF. WTF? WTF! ...

CPU killer in Java with JavaFX GUI client

Motivation Few weeks ago I was searching for a source of a bug in one of our applications. The QA team suspected that slow computer could be a reason for this. You know that - developers have Core i7 CPU with 8 GB RAM (at least some of us :-) ) and never realize, that users can have slow machine, which reacts differently . And for that tiny moment you would need slow computer, just to see how it works and whether you can break it. But how to achieve this? The QA team does that by creating a virtual machine and setting it very low resources, so it acts very slow. Another option is to use some kind of CPU killer – those are great pieces of software, doing exactly what it sounds – killing your CPU. There are tons of complete solutions out there, but I didn’t want to deal with the licensing and our IT stuff yelling at me, what is that software that I installed by myself again. So I decided to break the rule “ Don’t reinvent the wheel ” again. Requirements At first, here is a list ...