Posts

Showing posts from January, 2013

Java Memory Model and optimisation.

Overview Many developers of multi-threaded code are familiar with the idea that different threads can have a different view of a value they are holding, this not the only reason a thread might not see a change if it is not made thread safe.  The JIT itself can play a part. Why do different threads see different values? When you have multiple threads, they will attempt to minimise how much they will interact e.g. by trying to access the same memory.  To do this they have a separate local copy e.g. in Level 1 cache.  This cache is usually eventually consistent.  I have seen short periods of between one micro-second and up to 10 milli-seconds where two threads see different values.  Eventually the thread is context switched, the cache cleared or updated.  There is no guarantee as to when this will happen but it is almost always much less than a second. How can the JIT play a part? The Java Memory Model says there is no guarantee that a field which is not thread safe will ever

Should Java be more high level or low level?

Overview Java 8 is bringing much antisipated features such as Lambda expressions, Type Annotations and Virtual Extensions . While this functionality is a) valuable, b) playing catch up with cooler languages, are these richer, higher level functionality the only area Java should be focused. What are the most widely used languages There are many ways to assess which are the most widely used languages. One index which attempts to consider a wide variety of sources is the Tiobe Index . The positions and ratings are taken from Jan 2013. Position Programming Language Ratings Age Cooler Level 1 C 17.9% older no lower (much) 2 Java 17.4% same no same 3 Objective-C 10.3% older no lower 4 C++ 9.1% older no lower 5 C# 6.2% newer yes lower (slightly) 6 PHP 5.5% older yes higher 7 (Visual) Basic 4.7% older no same? 8