With a busy rest of the summer ahead of us, it was good to get another mountain done. Hopefully we’ll find some time in the superior hiking months of September and October to knock off a few more!
Future Interrupted
I always thought of Java’s Future interface as a fairly elegant and effective way of dealing with asynchronous tasks. It’s lightweight, gives you a mechanism to check if a task is finished, allows you to block until the task completes and retrieve its result, and also provides a hook to attempt to cancel the task via interruption. When used in conjunction with the various thread pool services in java.util.concurrent package, it becomes a simple, yet powerful tool.
Yesterday, though, I discovered a subtle distinction about the semantic behavior of the Future interface that slightly diminishes its power. I found myself in a situation where I wanted to cancel a Future, but then still wait until its associated task has completed. Initially I thought this might be accomplished with something like this:
// send an interrupt to the task's thread future.cancel(true); // block until the task is complete boolean finished = false; boolean interrupted = false; while (!finished) { try { future.get(); finished = true; } catch (CancellationException ce) { // task has been cancelled, handle appropriately finished = true; } catch (ExecutionException ee) { // task completed with error, handle appropriately finished = true; } catch (InterruptedException ie) { // current thread has been interrupted, record and continue interrupted = true; } } // re-interrupt this thread if we've been interrupted if (interrupted) { Thread.currentThread().interrupt(); }
Essentially, call cancel(true) on the Future in order to send an interrupt to the associated task’s thread. Then call get() on the Future in a loop to ensure that the task has properly handled the interruption and completed execution before proceeding. However, the above code does not work as expected. The problem is that once you call cancel() on a Future, the task’s thread will be sent an interrupt if it is running, but then the state associated with the task is completely cast aside. Subsequent calls to get() on the same Future will always immediately throw a CancellationException and there is no available mechanism to block until the task’s thread has completed handling the interruption and finished its execution.
The worst part about this is that it is not immediately clear from the javadoc for the Future interface that this is the actual behavior. The description of the cancel() method is very clear that if the task has not started, it will prevent it from starting, but if it has already started, it can make an attempt to “cancel” it via interruption of the task’s thread. Of course, since in Java interrupting a thread is only a suggestion for it to actually stop what it’s doing, there’s no guarantee about when or if the task will actually stop unless you handle the interruption properly. Therefore, I hoped that calling get() would wait for the computation to complete, and then throw a CancellationException if the thread was interrupted. After testing it and also digging through the Java source code for the Future implementation, I discovered that that is definitely not the case.
I struggled for a bit to come up with a reasonable alternative mechanism for accomplishing this behavior short of re-implementing my own thread pool and managing the threads myself. Fortunately, after speaking with a colleague, I was pointed to the beforeExecute and afterExecute hooks on the ThreadPoolExecutor. It takes a little more work then I had hoped, but using those hooks allows you to augment the functionality of ThreadPoolExecutor to achieve this type of behavior. I’ll leave the details of it up to you.
Anyhow, that’s my tidbit for the day. Be careful when playing with the Future!
What’s Next?
So what’s next for me? I’m happy to say the initial trauma of being laid off is gone, but not without sentiment. Sun Microsystems is the first company that I worked for as a fresh, green college graduate, and I like to think that my experiences there took a very unique path. I started off as a QA Engineer, automating tests for hardware products used directly by paying Sun customers. From there, I transitioned into a tools developer role, developing and supporting an automation framework used by the rest of the QA team(s). My “customers” while in that role were all internal Sun employees. Finally, I moved into Sun Labs on the Project Darkstar team, where technically, as a research project, we didn’t have any customers. In practice, though, we provided direct support to users through the open source community. While going through it all, it seemed like a very natural progression for my career; but looking back, I realize that it’s a real valuable trifecta of experiences that not many are fortunate enough to claim.
It was very hard for me initially when Project Darkstar was canceled; it was more than just the obvious emotions that come with losing your job though. There’s one other experience from my past that I can compare it to. The circumstances were different, but the feelings and the emotions were eerily similar. For four years while at RPI, I was a member of the track and field team. It was more than just an extra-curricular for me, though, it was my primary focus. I was a highly competitive, contributing member of the team, and was one of the team captains in my final season. Each of the four years that I was there, we won the NYSCTC outdoor state track and field championships; I felt like I was part of something great. The 2005 ECAC championships was my final track meet in my collegiate career. Even though I knew going into it that the meet would be my last, I was not prepared for the emotions that I would feel afterwards. For four years I was part of something great, and just like that it was over. I still remember lying in bed that night, surprised at my own tears.
With Project Darkstar, I also felt like I was part of something great. Not only was it a great project, not only were we driving towards a goal that had never been achieved before, but we were also a great team. There were such a unique set of personalities on that team that all meshed together to form a sum greater than its parts. Not only that, but we were nestled inside of Sun Labs, which is probably one of the smartest collection of people you’ll ever find. The way that it was all torn away from us, so harshly and abruptly, and when we were so close to our goal, is what made it so difficult. Once again, I had established my place in something that was great, and just like that it was over.
It’s time to move on, now, though. If I’ve learned anything from my past it’s that there’s always something great waiting in my future. I’ve accepted a new position as a software engineer at Nokia and am actually very excited to begin work on Monday. I’ll be working on some scalable caching and indexing infrastructure for their service platforms, and am looking forward to a new and interesting challenge. I also plan to continue working on Project Darkstar’s successor, RedDwarf Server in my own personal free time. I obviously expect my available time to devote to that effort to be considerably more limited than it has been, however.
Things are looking up, and I’m looking forward to my next great thing.
Oh LaTeX how you taunt me
Here’s a good one. Since I’m currently unemployed and looking for a job, naturally I’ve been sending resumes out. I’ve used LaTeX to generate my resume for years now, and it has always worked out quite well. However, today I had a need to print out my resume, and when I did, I noticed that the font seemed slightly too small, and that the right margin seemed a bit too big. It looked fine on the screen in my PDF viewer, but not on the physical printout. Hmm. As it turns out, I accidentally generated the PDF file with A4 size paper and all of the electronic versions I have sent out thus far have been this A4 version. Grrrr!
I must have come across and handled this issue before, but at least on my Ubuntu installation, PDF documents generated by sequential latex, dvips, and ps2pdf commands default to A4 size paper. In order to get the correct US style letter paper, I have to explicitly use the “-t letter” option in dvips. After rooting around a bit, the command “texconfig paper letter” has changed my default system paper size for dvips, dvipdf, xdvi, and hopefully I’ll never make this mistake again!
P.S. Metric system? One day we will give in to your logical structure and simple unit conversion. Clearly, though, that day is not today.
Still Playing Ultimate
Repeat visitors to this blog may be wondering: what happened to my frequent ultimate frisbee status updates? Well, the status updates may have petered out, but that doesn’t mean I’m not still playing. I’m still very much attending the regular Monday, Wednesday, and Friday lunchtime pickup games in Burlington. It’s business as usual in that department. In fact, I’m kind of regretting not signing up for the BUDA winter indoor hat league that’s currently underway in Milford. It’s probably for the best that I missed the boat on that though as while I really loved playing in that league the previous times that I’ve done it, that indoor turf can be pretty brutal on the knees and feet.
Anyhow, one other bit of ultimate news is that Walter Fredrick Morrison has died at the age of 90. Morrison is regarded as the “father of the frisbee”. And to reinforce the notion that the sport is dominated by geeks, the story was picked up by Slashdot and hit the front page a couple days ago.
I always thought that Marty McFly invented the frisbee in 1885 though…
RedDwarf
As I mentioned previously, I do intend to continue working on Project Darkstar part-time at least while I search for new employment opportunities. Not only will it allow me and whoever else is interested push along the original goals of the project, but it will also give me a perfect place to keep my skills sharp while I’m out of work. Selfless and selfish reasons, molded into one. However, it does not seem appropriate to continue working using what are now Oracle’s resources and contributing code to Oracle’s official repository. Not only are there questions about outside contributions, but there are also no guarantees about how long Oracle’s official repository will remain active. So I am going with an equally reasonable and open-source-y alternative.
I have established what I hope will become an official community fork of Project Darkstar. This fork will go by the name RedDwarf and is hosted as a sourceforge project. I cannot take credit for the new name, as it was dreamt up by the original instigator of Project Darkstar at Sun Labs (Jeff Kesselman), but I do hope that it will become an even more well known name than Project Darkstar ever was in the games industry. So without further adieu, here are the new community guidelines:
- The sourceforge project is used to host what were once three separate projects on java.net. The reddwarf-server, reddwarf-shared, and reddwarf-java-client all live in the same subversion repository, but under completely separate sub-trees, each with their own trunk, branches, and tags.
- The development process should remain largely unchanged from Project Darkstar. All commits to any trunk repository must undergo a thorough review by at least one other committer, and commit privileges are earned. Review requests should be sent to the mailing list: reddwarf-develop on sourceforge.
- All design, support, and informational documents should go in the Trac instance hosted at sourceforge.
- All issues and bugs should be filed as a ticket in Trac.
- Forum discussions should continue as usual on the sourceforge hosted forums.
- Releases will be done periodically as appropriate. All releases will be published to the central Maven repository rather than the java.net Maven repositories. (This is my first task and may take some time). They will also be published as files for download on the sourceforge site.
Progress will be much slower than before, but I think it’s very important to maintain the structure and code quality standards that we had established as a fully funded project. Will anything come of this effort? I’m not sure. But I think it’s the best chance for coordinated progress to continue with Project Darkstar.
Shocking News
It’s been a while since I posted anything on this blog, and I wish my return was the result of better circumstances but no such luck: my position at Sun Microsystems has been eliminated, and as a result I have been let go. It is ironic that the European Union’s lengthy delay in approving the Oracle-Sun acquisition gave the Project Darkstar team and community such a long, uninterrupted stretch of time to make some unbelievable progress towards our goals. However, once the deal did finally close, the decision had already been made that Oracle will discontinue investing resources in the project, and so here I am: newly unemployed.
I must say that the shock and disbelief of learning that you’ve been laid off is a predictably emotional time. Of course I didn’t think it would happen to me, but it did: proof that job security is all but an illusion. They say losing your job is like dealing with any other type of loss, which is absolutely true. Knowing this doesn’t make it any easier though. Despite this difficult situation, however, I have received nothing but support from my family, friends, colleagues and even people who were previously just casual acquaintances. Thank you to everyone who has been there so far; I know for a fact I’ll come out the other side of this a strong person.
As for my future, and the future of Project Darkstar? Well both are uncertain. I have already started ramping up and preparing for a full scale job search in the hope that I will find something even better than the best job I’ve ever had. In terms of Project Darkstar, a core group of former members of the team have already started exploring alternative ways to keep the project going. This includes both potential for-profit and volunteer efforts to carry out the original mission objectives laid out years ago. At the very least, after getting myself organized, I personally intend to continue working on the project on a part-time basis during my job search and hopefully beyond. More details to come…











Posts