What's New Here?


The Test Waste Ratio

Remember the days when bugs were just part of life? I mean a big part. If you recall those dark ages, we’ve spent most of our time fixing bugs and introducing others. In our spare time, we got to work on new stuff. Today is different, there are a lot less bugs. So we get to work more on the new stuff, right? Or have we found a new replacement for them?     Test Maintenance Is the New Bug You wake up one morning, and you discover that you spend 25% on maintaining tests. True story. This doesn’t happen in one day, you feel more work on tests creeping up, and you feel it’s just natural. Part of the work. Then one day you actually look at the numbers. And someone needs to pick you off the floor. Nobody Writes Bad Tests Intentionally So, where do these tests come from? These tests are the creaky windows in the attic. One gust of wind, and you hear a loud bang. You need to go up there and fix them. Again. Much like those windows, they don’t give you much protection. Since they break once in a while, you get accustomed to them creaking and banging, you don’t notice them anymore. Which is bad, since sometimes they let some real menaces into the house. Like real bugs. But you won’t know because you’re sure it’s the ol’ window moving in its place. So until you face reality, it’s not clear how much they cost us. It could amount to a lot. Back to Test World Let’s call these bad tests the “wasteful” tests. Which begs the question: If those cause waste, when are tests valuable? What exactly is this value? This is hard to quantify. A test is valuable if it catches a bug. It gets points for that. So, ridiculous as it may sound, the time spent on fixing bugs the tests found is an indicator to the value of the test. We can call those tests the “valuable” tests. Now, here’s the Test Waste ratio:The denominator is the total time spent due to tests breaking, the valuable and wasteful. The numerator is the wasteful work. If your wasted time is large, the ratio gets closer to 1. If it’s small, it gets closer to zero. You want to get a lower ratio as possible. It’s not really up to you, but it’s an indicator. And those numbers can actually be measured. So Much For Theory What do you think? Does it make sense? Is it helpful in any way? Do I stand a chance for a Nobel prize? Let me know. PS. Next week, I’m going to be at Belgium Testing Days. Apart from the Spaceship I’m smuggling through customs, I’m going to be part of an interactive session, talking about the ROI of test automation.   Reference: The Test Waste Ratio from our JCG partner Gil Zilberfeld at the Geek Out of Water blog. ...

A Template for Formulating Great Sprint Goals

Summary Working with sprint goals is a powerful practice. But many product owners and teams don’t leverage sprint goals or don’t apply them correctly: Sprint goals often state the stories to be implemented rather than the reason for undertaking the iteration. That’s rather unfortunate: Effective sprint goals serve to test ideas, to deliver features, and to foster teamwork. This post introduces a sprint goal template to help you write powerful sprint goals to build great products. I find it helpful to consider three questions when choosing a sprint goal: Why do we carry out the sprint? How do we reach its goal? And how do we know that the goal has been met? My sprint goal template therefore consists of three main parts: the actual goal, the method employed to reach the goal, and the metrics to determine if the goal has been met. It additionally provides a header section that allows you to state to which product and sprint the goal belongs, as the picture below shows. You can download the template as a PDF from romanpichler.com/tools/sprint-goal-template/ or by clicking on the image below.The template above has grown out of my experience of working with Scrum for more than ten years, and it is inspired by the scientific method and Lean Startup. Let’s have a look at the template sections in more detail. The Goal Section The goal section states why it is worthwhile to undertake the sprint. Examples are:Test an assumption about the user interaction and learn what works best for the user, for instance: “Will users be willing to register before using the product features?” Address a technical risk such as: “Does the architecture enable the desired performance?” Release a feature, for instance: “Get the reporting feature for general release.”The sprint goal hence differs from listing the user stories that should be implemented. It communicates the reason for carrying out the work, and it provides a motivation for running the sprint. The sprint goal should be shared: The product owner and the development team should believe that working towards the goal is the right thing to do. To choose the right sprint goal I find it helpful to consider the amount of uncertainty present. In the early sprints, addressing risks and testing assumptions allows me to learn about what the product should look like and do and how it is built. Once the key risks and critical assumptions have been dealt with, I like to focus on completing and optimising features, as the following picture shows:The Method Section This section addresses the question of how the goal is met. The default Scrum answer is simple: Create a (potentially shippable) product increment using the high-priority product backlog items, and demo it to the stakeholders in the sprint review meeting. But writing software and employing a product demo are not always the best methods to achieve the goal! A paper prototype can be good enough to test a visual design idea or an assumption about the user interaction, for instance. What’s more, other methods such as carrying out a usability test or releasing software to run an A/B test may well be more effective than a product demo. You should therefore carefully choose the right method and state it in this section. But don’t stop there. Determine the test group, the people who should provide feedback and data. Who these individuals are depends on the sprint goal: If you are validating an assumption about the visual design, the user interaction or the product functionality, then you probably want to collect feedback and data from the users. But if you are addressing a technical risk, then users may not be able to help you. Consider inviting a senior developer or architect from another team instead. Stating the test group clarifies who “the stakeholders” are, who is required to provide feedback so that the right product is developed. The Metrics Section The metrics section communicates how you determine if the goal has been met. Which metrics you use depends on the method chosen. For a product demo, you may state that at least two thirds of the stakeholders present should respond positively to the new feature, for instance; for a usability test, at least three of the five testers are complete the task successfully in less than a minute; and for the release of a new feature, you might say that at least 80% of the users use the new functionality at least once within five days after launching the feature. Whichever metrics you choose, make sure that they allow you to understand if and to which extent you have met the goal. The Header Section The header section consists of the two subsections “Product” and “Sprint”. They simply allow you to state which product and which sprint the goal belongs to. Customise this section according to your needs. If you work for an agencies or an IT solution provider, you could replace “Product” with “Project”, for instance. User Stories and the Sprint Goal You may be wondering how the template relates to the user stories. Let me first reiterate that your sprint goal should differ from your user stories. The goal explains the why it is a good idea to carry out the sprint an implement the stories. The user stories enable you to reach the goal. It’s a common mistake to confuse the two. To connect the template and the stories you have two options: You can state the relevant user stories in the template’s method section, or you can list them separately on the sprint backlog, as the following picture illustrates.In the picture above, the sprint goal is stated on the left to the sprint backlog, which lists the user stories and the tasks required to meet the goal in form of a task board.   Reference: A Template for Formulating Great Sprint Goals from our JCG partner Roman Pichler at the Pichler’s blog blog. ...

Are comments always wrong?

A colleague asked me recently: Why aren’t developers writing comments any more? He’d been looking through some code his team had written, and couldn’t understand it – he was looking for comments to make sense of the mess, but there were none. Before he challenged the team, he asked my opinion: should developers be writing comments? Excessive Comments When I started programming some years ago, I would comment everything, and I mean everything.     // Add four to x     x += 4; My logic at the time was that it was impossible to tell the difference between uncommented clear code and gnarly code you just hadn’t spotted the gnarliness in yet. So I would comment everything, where the absence of a comment meant I’d forgotten – not that it was so trivial as to not warrant mentioning. No Comments Eventually I started working with peers who knocked some sense into me, and I immediately halved the number of lines of code I produced. At first it was a shock, but soon I realised that clear code is easier to read if there’s just less noise. And this is all (most) comments become: noise. Sometimes they’re accurate, sometimes they’re not. But you can’t rely on them, you always have to assume they might be wrong. So if the code and the comment seem at odds, you assume it’s the comment that’s wrong and not your understanding of the code (naturally you’re infallible!) Clean Code Uncle Bob and the notion of clean code have taken “no comments” to an almost fanatical zeal. But every time I get into an argument with someone about how maybe this time a comment might be justified: Ctrl-Alt-M, enter your comment as the method name and it makes the code more obvious. Every. Damned. Time. However, the trouble with a zealous argument like this is it gets taken up by asshats and lazy people. It’s too easy to say “if you’d read Clean Coder you’d know you don’t need comments. Quit living in the past, grandpa!”. Uh huh. But your code is still a muddled pile of indecipherable crap. At least with comments there’d be some signposts while I wade through your steaming mess. Some Comments The truth is: sometimes comments do help (squeal clean code weenies, squeal!) There are some cases where extracting a method name isn’t sufficient. Sometimes having 20 one line methods in my class does not make it easier to read. The end goal is to produce understandable code. Generally, naming things properly helps. Adding comments that get stale does not. But that doesn’t mean that writing crap code and not commenting is the answer. Don’t use “no comments” as an excuse to leave your code indecipherable by human beings. For example, sometimes you need to document why you didn’t do something. Maybe there’s a standard way of converting between currencies in your application – which this one time you’ve deliberately not used. A comment here might help future people not refactor away your deliberate choice (even better is baking your decision into a design – some class structure that makes it really obvious). Sometimes a method name really doesn’t do a line of code justice, it’s better to be seen in the context of the lines before and after it – but it really needs some explanation of what you’re doing. This is particularly true when dealing with complex algorithms or mathematical formulae. Getting the Balance Right How do you get the balance right? Well, your goal is to make code that other people can understand. The best way to get feedback on that is to ask someone. Either have explicit code reviews or pair program. If another human being has read your code and they could understand it – there’s a better than average chance that most other capable people will be able to read it too.   Reference: Are comments always wrong? from our JCG partner David Green at the Actively Lazy blog. ...

Choosing a leader like an agilist

The leader as a captain I recently read Petri Kainulainen’s article on sharing leadership among team members and I am on the same wavelength in this regard, since the Agile methods emphasizes the importance of “motivated individuals, who should be trusted”. While a team leader could be regarded as a reminiscence of the old rigid organization structures, I still see many benefits of having such a captain. When it comes to improving my people skills, I like to get inspired by other domains of activity that have been struggling with the very same challenges for decades. Think about the greatest sport teams, where all team members are stars, and yet they always have a captain for:the captain is the role-model for every team member he leads by example he always mediates conflicts, knowing that prevention is always better than curing he welcomes and facilitates new team members integration he never loses his temper in times of trouble, he is the voice of the team he is constantly goal-oriented, making sure the team is on the right trackThe leader is nominated by the team But a great captain is always chosen by the team members. That’s the most natural way of nominating a leader and a leader doesn’t have to be imposed. This is how a team leader should be chosen in our industry as well. Self-organizing teams need to have the power of deciding their leader as well. A leader is not someone who once proved his abilities, but a person who constantly validates his role. The team leader position is always backed by the team members feedback. A good leader is therefore self-reinforced by his positive actions, while a bad leader is simply replaced by someone with better skills. The voting process This is my recipe for choosing a team leader:The team must first understand what a good leader means. The voting is not a popularity contest. The team is always held responsible for their actions and choosing their leader is no different Allow the team members to register for the leader election. If you never wanted to be leader, there is little chance you’d ever become a great one Let everybody vote and explain their reasons for choosing a given team member. Without any reasonable explanation the voting could easily turn into a popularity contest Respect the decision even if the new leader is not who you thought of, in the first placeConclusion We need to trust our teams and respect their opinions. I like this approach since it’s a very good way of spotting leaders that you weren’t aware of. People with leadership potential are rare gems and I always stay open-minded to any method that can bring me the next great leader.   Reference: Choosing a leader like an agilist from our JCG partner Vlad Mihalcea at the Vlad Mihalcea’s Blog blog. ...

Clean SWT Listener Notifcations with SWTEventHelper

Writing tests for SWT based UIs often requires to notify widget listeners programmatically. Unfortunately the code to create, initialize and finally to trigger the event is a bit verbose and distracts from the actual purpose of the test. After writing similar initialization routines a couple of times I came up with a little utility class that avoid these redundancies and make the code somewhat more expressive1 The class is called SWTEventHelper and uses a fluent interface coding style combined with static imports2 as known for example from Mockito. The following snippets demonstrate the usage by a simple example:     public class MouseDownCounter extends MouseAdapter {private int count;public MouseDownCounter( Control control ) { control.addMouseListener( this ); }@Override public void mouseDown( MouseEvent event ) { count++; }public int getCount() { return count; } } Looking at the code of the MouseDownCounter one may consider it necessary to ensure that a mouse down event actually increases the count by one. With the SWTEventHelper a test to do so could look like this: public class MouseDownCounterTest {@Rule public final DisplayHelper displayHelper = new DisplayHelper();@Test public void testMouseDownIncreasesCount() { Composite parent = displayHelper.createShell(); Control control = new Label( parent, SWT.NONE ); MouseDownCounter counter = new MouseDownCounter( control );trigger( SWT.MouseDown ).on( control );assertEquals( 1, counter.getCount() ); }[...] } The test creates a ‘real’ SWT control3 in the build4 section of the test. After that the control is ‘wrapped’ by our unit under test, the MouseDownCounter. The following operate section creates a SWT.MouseDown Event using SWTEventHelper#trigger(int) and the listener that got registered at the Label control is notified via SWTEventHelper#on(Widget). Last but not least the check section ensures that the mouse down has actually increased the counter. The SWTEventHelper furthermore provides a configuration method for each attribute of org.eclipse.swt.widgets.Event. Look at the following line of code to see how to fire an event notification with e.g. a certain Event#keyCode: trigger( SWT.MouseDown ).withKeyCode( SWT.BUTTON1 ).on( control ); As I have used this little helper for over a hundred times now it might be useful for others too. Hence I set up a GitHub gist where you can download the SWTEventHelper code: https://gist.github.com/fappel/9426554 Don’t be shy, give it a try!Expressiveness is of course, at least to some extend, in the eye of the beholder Eclipse offers the possibility to configure content assist with static imports via the favorites preference settings which makes this approach even more comfortable The DisplayHelper reduces typing effort by handling Display related initialization and disposal automatically. You can find a description and a download link in the post A JUnit Rule to Ease SWT Test Setup The test formatting is based on the BUILD-OPERATE-CHECK pattern (Robert C. Martin, Clean Code, Chapter 9, Clean Tests). However in a real world scenario I would probably extract the build section into a separate method  Reference: Clean SWT Listener Notifcations with SWTEventHelper from our JCG partner Frank Appel at the Code Affine blog. ...

Red Hat officially announces release of JBoss BPM Suite 6 and JBoss BRMS 6

Red Hat has just announced general availability of these long awaited products! It takes a large effort to turn the community code into enterprise quality software that customers and end-users can rely on in production with Red Hat support. It is now a great time for current and potential customers to learn about the product, for partners to start engaging with it and learning the nuts and bolts, and for the open source community and Red Hat to receive all sorts of input on these products; all of which turns them into better products to use with the world-class customer service Red Hat has gotten us used to. The new JBoss BPM Suite has a well defined, integral focus on process management and automation. It represents the culmination of an awesome amount of work done by the open source community over many months. It contains not only improvements on existing components, not only a completely redesigned look and feel, but also a set of exciting new features! It’s new, but it maintains backwards compatibility with your previous JBoss BRMS business process and rules project implementations. It also offers with your subscription the world class Red Hat JBoss support of your production environment you are familiar with. JBoss BPM Suite 6 also represents the final phase in the integration of Polymita into Red Hat. That’s why you will find advanced functionalities such as dynamic data and forms modeling. This innovative feature lets you manage those directly from the web interfaces of the tool without coding! Another cool new thing derived from the acquisition is the Business Activity Monitoring. Now you are able to create beautiful dashboards by dragging and dropping on a web interface with all sort of rich graphics that are linked to the processes. In addition, BPM Suite now also includes the entire state-of-the-art BRMS 6 product with its advanced decision management and data analysis capabilities, which is also a separate product in itself that you can continue to use with its own support subscription. So now it’s your turn! Discover how these new products can contribute value to your organization! Download Links:JBoss BPM Suite 6.0 – https://access.redhat.com/jbossnetwork/restricted/listSoftware.html?product=bpm.suite&downloadType=distributions JBoss BRMS 6.0 – https://access.redhat.com/jbossnetwork/restricted/listSoftware.html?product=brms&downloadType=distributionsDocumentation:JBoss BPM Suite 6.0 – https://access.redhat.com/site/documentation/Red_Hat_JBoss_BPM_Suite/ JBoss BRMS Suite 6.0 – https://access.redhat.com/site/documentation/Red_Hat_JBoss_BRMS/Web Pages:JBoss BPM Suite: http://www.redhat.com/products/jbossenterprisemiddleware/business-process/ JBoss BRMS: http://www.redhat.com/products/jbossenterprisemiddleware/business-rules/BPM Example App: A fully functional BPM Example Application is included as part of the downloads.   Reference: Red Hat officially announces release of JBoss BPM Suite 6 and JBoss BRMS 6 from our JCG partner Eric Schabell at the Eric Schabell’s blog blog. ...

Java 8 : What do developers think?

Since Java 8 releasement countdown is starting, Java developers seem certainly ready to get involved. According to a survey in Typesafe, 65% of developers who participated answered that they will be migrating to Java 8 in a 24 months plan, and from them 30% will try to migrate over the next 6 months. 73% of developers who participated are currently working with Java 7, whereas there is a 22% part working still with Java 6. And from those working with Java 6, only 44% are planning to move straight to Java 8. As far as Lamdas are concerned, this new feature of Java 8 is welcome by the Java community, since 83% of developers stated that the lambda expressions and virtual extension methods are the two new features most expected. Devs are also excited with concurency updates (16%) and the new Date and Time API (15%). 48% of devs believe that lambda injection will positively reinforce the adoption of Scala. Java Security has been the big problem where Oracle has focused, and was also the basic cause of the Java 8 release delay. Focusing on better securing the Java platform was the main reason for last year’s decision to delay shipment of Java 8. Oracle seems to have focused on the major bugs, but after all a good job is done, since now an important 59% part of developers believe that these problems have been solved. Oracle has done a good job with the JVM front too, with 98% of users employing it. ...

How to create MySQL DataSource in WebLogic Server

One cool thing about using an application server is that it allows you to create DataSource outside of your application and it can manage it along with thread pool and transaction manager etc. With WebLogic Server, it comes with quite a few built in JDBC drivers such as Oracle Database and MySQL etc ready for your use. Here I will show you how to create a MySQL DataSource.            Login into http://localhost:7001/console On the left menu click Services > Data Sources On the right, click “New” button Enter Name: mysql_ds ; You may optionally give it an JNDI Name: jdbc/mysql_ds; And then select Database Type: MySQL Click “Next” button and then accept default with another two “Next” buttons. Now enter Database Name: test; Host Name: localhost; Database User Name: root; and then the password. Click “Next” and you may optionally test your connection here. Click “Next” and you MUST select an sever as target! Click “Finish”Now you have a DataSource ready to be used by your application on this server. You may access this by either JNDI lookup, or JPA configuration with entity manager injection. TIPS: If you do not pick a server Target in step 8, then your applicatoin will NOT able to access this Data Source! So ensure you have done this step as it’s the easy step to miss.   Reference: How to create MySQL DataSource in WebLogic Server from our JCG partner Zemian Deng at the A Programmer’s Journal blog. ...

Logging or debugging

Debugging is lame. You should debug log. If your code is structured you do not need debug logging. These are two opinions from the two ends of the line. I am, as usually, standing in the middle, and I will tell you why. First of all, there is no principal difference between debugging versus logging. They are just two different implementations of the same thing: observation of your execution engine state in time dimension. Issue with debugging When you debug you step your program forward in time and at any point the execution stops you can examine the value of any variable. The shortage is that you can not step back in time. At some points you realize that you would just like to see what the value of a certain variable was just before some method was called, some object was created or whatsoever happened in the system. What you actually do in such a situation is to restart the code and hoping it behaves deterministic try to catch the execution at the earlier stage that you are interested in. And this is another shortage of debugging. You can not effectively debug a code that does not behave deterministic. And trust me: most bugs behave non deterministic. Issue with loggingWith logs the major issue is different. It is not the time but rather the breadth of states, variables that you can look at is the problem. You insert log statements into your code dumping the values of variables into a log file at a certain point of execution. When you examine the log file you can scroll back and forth. However if you did not print out the value of a certain variable at a certain execution point, there is no way to get it from the log file. The solution is the same as with debugging: execute the code again, this time extended with the new log statements. If, however, you have enough information in your log files, then you will just get enough information to track down a bug even if that is not deterministic. Only ‘if you have’ … Solution: logging all the states all the times? The ideal solution would be to dump all variables into a possibly binary log file at each state of the execution and examine the content of the file afterwards. The examination would essentially look like a debugger, except that the change of the variables comes from the recorded log file instead of from on the fly calculation. It would be like a playback of a recorded execution and as such you could replay it several times. I do not know if there is any tool like that for the JVM. You just can not define what is “each state” effectively in a multi thread execution environment like the JVM is. This is one of the issues. The other thing is that if you’d start dumping the JVM memory after each command (forgetting the issues of multi-thread) it would require enormous amount of bandwidth and disk space. Dreaming about the ideal solution not deliverable is sort of no use. What is the solution that can practically be executed? Practical approach You can debug when it is appropriate. Full stop. You just did that so far, keep doing that. I tend to use log statements even when I debug some code and if the environment allows it I do it on the fly. When I find the root cause of the issue I am hunting I review the log statements and I delete them. They did the job while debugging, they are not needed anymore. At least that was my practice unit I found myself writing log statements that I have already created before. Why? Because fixing one bug does not mean that I have fixed all of them. There is nothing like all bugs fixed. But the log items littered the log file and that just increased the work to find the needed information hunting the next bug. In other words the log file is full of noise and that is why I deleted these items the first place. But for the same reason I could also delete the unit tests that already pass. It would save a lot of time during compilation, wouldn’t it? We do not do that. Summary in one sentence? Log and debug the way it fits you and the issue you are hunting.   Reference: Logging or debugging from our JCG partner Peter Verhas at the Java Deep blog. ...

Java 8 Friday Goodies: Easy-as-Pie Local Caching

At Data Geekery, we love Java. And as we’re really into jOOQ’s fluent API and query DSL, we’re absolutely thrilled about what Java 8 will bring to our ecosystem. We have blogged a couple of times about some nice Java 8 goodies, and now we feel it’s time to start a new blog series, the… Java 8 Friday Every Friday, we’re showing you a couple of nice new tutorial-style Java 8 features, which take advantage of lambda expressions, extension methods, and other great stuff. You’ll find the source code on GitHub. Java 8 Goodie: Easy-as-Pie Local Caching Now get ready for one of the most awesome revelations in this series so far. We’ll show you an easy-as-pie way to implement a local cache using the good old ConcurrentHashMap and lambda expressions. Because, Map now has a new way of a atomically calculating a new value in case a key is absent. Perfect for caches. Let’s delve into code: public static void main(String[] args) { for (int i = 0; i < 10; i++) System.out.println( "f(" + i + ") = " + fibonacci(i)); }static int fibonacci(int i) { if (i == 0) return i;if (i == 1) return 1;System.out.println("Calculating f(" + i + ")"); return fibonacci(i - 2) + fibonacci(i - 1); } Yes. That’s the naive way of doing things. Even for small numbers like fibonacci(5), the above algorithm will print out a huge amount of lines, as we’re repeating the same calculations exponentially: Calculating f(6) Calculating f(4) Calculating f(2) Calculating f(3) Calculating f(2) Calculating f(5) Calculating f(3) Calculating f(2) Calculating f(4) Calculating f(2) Calculating f(3) Calculating f(2) f(6) = 8 What we want to do is build a cache of previously calculated fibonacci numbers. The most straightforward technique is to memoize all values in a cache. Here’s how we build a cache: static Map<Integer, Integer> cache = new ConcurrentHashMap<>(); Done! As mentioned before, we’re using the newly added Map.computeIfAbsent() method to calculate a new value from a source function only if we don’t already have a value for a given key. Caching! And since this method is guaranteed to execute atomically, and since we’re using a ConcurrentHashMap, this cache is even thread-safe without resorting to manually applying synchronized anywhere. And it can be reused for stuff other than calculating fibonacci numbers. But let’s first apply this cache to our fibonacci() function. static int fibonacci(int i) { if (i == 0) return i;if (i == 1) return 1;return cache.computeIfAbsent(i, (key) -> fibonacci(i - 2) + fibonacci(i - 1)); } That’s it. It can’t get any simpler than this! Want proof? We’ll log a message on the console every time we actually evaluate a new value: static int fibonacci(int i) { if (i == 0) return i;if (i == 1) return 1;return cache.computeIfAbsent(i, (key) -> { System.out.println( "Slow calculation of " + key);return fibonacci(i - 2) + fibonacci(i - 1); }); } The above program will print f(0) = 0 f(1) = 1 Slow calculation of 2 f(2) = 1 Slow calculation of 3 f(3) = 2 Slow calculation of 4 f(4) = 3 Slow calculation of 5 f(5) = 5 Slow calculation of 6 f(6) = 8 Slow calculation of 7 f(7) = 13 Slow calculation of 8 f(8) = 21 Slow calculation of 9 f(9) = 34 How would we have done it in Java 7? Good question. With lots of code. We’d probably write something like this using double-checked locking: static int fibonacciJava7(int i) { if (i == 0) return i;if (i == 1) return 1;Integer result = cache.get(i); if (result == null) { synchronized (cache) { result = cache.get(i);if (result == null) { System.out.println( "Slow calculation of " + i);result = fibonacci(i - 2) + fibonacci(i - 1); cache.put(i, result); } } }return result; } Convinced? Note, that your actual solution would probably make use of Guava Caches. Conclusion Lambdas are only one part of Java 8. An important part, but let’s not forget all the new features that were added to the libraries and that can be leveraged with lambdas now! This is really exciting and… We can greatly improve our code bases without resorting to new libraries. All of the above can be run with the JDK’s libraries only. Next week in this blog series, we’re going to look at how Java 8 will improve on the existing and new concurrency APIs, so stay tuned! More on Java 8 In the mean time, have a look at Eugen Paraschiv’s awesome Java 8 resources page   Reference: Java 8 Friday Goodies: Easy-as-Pie Local Caching from our JCG partner Lukas Eder at the JAVA, SQL, AND JOOQ blog. ...
Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

15,153 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books