ThreadLocalRandom.current().nextInt() ThreadLocalRandom.current().nextDouble() ...
Saturday, 17 November 2012
Java Random thread save
Examples:
TimeUnit class
If you want your java program to wait for defined time amount use class TimeUnit. It is more clean than using Thread.sleep.
Examples:
Examples:
TimeUnit.NANOSECONDS.sleep(10) TimeUnit.SECONDS.sleep(10)
Sunday, 4 November 2012
Guava light cache
If you have a need to declare a small cache which have to be cleared periodically you can easily do it using Guava Cache.
We have to define loader that will load cache element and a period after which it will throw an item away. And then next read will use a loader to load an element into cache again. We can also define a cache in the way it will throw away an item if it was not read for a period of time.
Here is an example:
We have to define loader that will load cache element and a period after which it will throw an item away. And then next read will use a loader to load an element into cache again. We can also define a cache in the way it will throw away an item if it was not read for a period of time.
Here is an example:
private LoadingCache<String, MyClass> cache; CacheLoader<String, MyClass> loader = new CacheLoader<String, MyClass> () { public MyClass load(String key) throws Exception { return ourService.get(key); } }; cache = CacheBuilder.newBuilder(). expireAfterWrite(1, TimeUnit.MINUTES). build(loader);
More about this subject here: http://code.google.com/p/guava-libraries/wiki/CachesExplained
Defining Mockito mock bean from Spring xml definition
You can define a spring bean in spring xml context that will be a Mockito mock of a given type:
But if you want to inject that bean by type, you have to define it as a Proxy of given interface:
com.example.Repository
Sunday, 28 October 2012
Monday, 15 October 2012
Monday, 8 October 2012
Velocity Europe
I have attended Velocity Europe Conference. Here is what I learned:
Tools for web performance
Tools for web performance
- YSlow - browser plugin showing how site can be optimized http://developer.yahoo.com/yslow/
- Chrome devtools plugin for site optimization
- Chrome enable benchmarking - a plugin to show load times with browser cache disabled http://www.chromium.org/developers/design-documents/extensions/how-the-extension-system-works/chrome-benchmarking-extension
- Web Page Test - a page testing site performance with improvements tips http://www.webpagetest.org/
- Google tools for page optimization https://developers.google.com/speed/pagespeed/
- Graphite - tool for visualization f.e. server performance metrics
- HTTP 2.0 - Will be decided what it will include in about a 1,5 year. It will be based mostly on SPDY
- Do not implement Javascripts that block. You can use option async + defer (for IE). Then it will not block your page load event, what makes your page beter for google robots and higher in google searches (Google has 3,5 seconds metric for Page Load). Every JS that does not block should be loaded in the bottom of the page and ones that block should be included on the top. Use Modernizr for javascript dependency
- If you add a resource in the page starting with https://address or http://address, just use //address
- Add performance metrics to DoD
- Allow business to measure RUM (Real user monitoring)
- Learn every day is the reason for working, otherwise change your work! (From facebook guy)
- Take risk. Otherwise you want learn. (Same guy)
- Site performance means money for business
- It is better to develop a native application on the mobile if you want a fully featured one. It is almost impossible to have one fast rendering on Android and IPhone.
- Do not keep server 200 days without restart. It is not updated or it can broke down. (That's why windows 95 had to be restarted. Some unix also had Magic number bug, so they worked only about 200 days)
- Some videos from the conference: http://www.youtube.com/playlist?list=PL8011D1E0D184CE09
- Google Compute Engine - virtual machines planned to release by google: http://slides.eightypercent.net/velocity-europe-2012/#1
- Free Tools to Help You Analyze Web & Mobile Performance - http://velocityconf.com/velocityeu2012/public/schedule/detail/26851
- Story describing that we have to measure not only single page loads but whole scenarios http://velocityconf.com/velocityeu2012/public/schedule/detail/26567
- W3C Status on Web Performance - http://velocityconf.com/velocityeu2012/public/schedule/detail/26705
An here is my photo: http://www.flickr.com/photos/oreillyconf/8071104092/in/set-72157631732025793
Subscribe to:
Posts (Atom)