The Future is here

OK, so at my job I’ve just learned about Java futures in the java.util.concurrency library.  They are pretty cool, but I’m new to them so I may be getting some things wrong.  I don’t need to instantiate huge numbers of threads anymore, but can simply use the Future object to handle it for me.  Future is an interface that contains methods to check if a computation is complete.  It kind of makes multithreading more simple.  Here’s a good tutorial:

There’s a few things that are needed when working with Futures.

1) ExecutorService or some kind of thread pooling

I think futures still use threads, and the ExecutorService helps manage them.  So instantiate an ExecutorService (import java.util.concurrent.ExecutorService;) like this:

   private final ExecutorService pool = Executors.newSingleThreadExecutor();</pre>   

2) An object of type runnable or callable that is submitted to the thread pool. This returns a Future.

private Future<String> getPreview(final ContentItem item) {
    return pool.submit(new Callable<String>() {
        public String call() {
              return fbPreview.generateAndStorePreview(item);

3) A Future object with a call of get(long timeout, TimeUnit unit)
throws InterruptedException,

The get function, according to the javadoc states that it “Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.”

Future<String> f = getPreview(item);

try {
   String url = f.get(30000, TimeUnit.MILLISECONDS);
   System.out.println("Preview generated at " + url);
} catch (TimeoutException te) {
   log.error("Facebook Preview generation for item: ? timed out. Continuing to error screen.", item.getId());
} catch (ExecutionException ee) {
   log.error("Facebook Preview generation for item: ? erred in execution. Continuing to error screen.", item.getId()); 
} catch (Exception e) {
   log.error("Facebook Preview generation for item: ? erred. Continuing to error screen.", item.getId());

So all in all, this is a way of doing some nifty threading without actually having to use threads and manage resources.


Two weeks in

Today marks the completion of the second week since I’ve gone back to software engineering.  In all honesty, it’s been a tough transition.  There are so many technologies to catch up on since I was last a programmer.  I find myself googling pretty much every new concept I see, not understanding the answer, then googling further until I can recurse back to the top.  Java code looks unfamiliar to me.  Or perhaps the code I was writing in the past was just unsophisticated and didn’t follow good design patterns.  But it was easier to understand, or so it seems.

I know starting this blog I stated all my grand ambitions to change law with software.  So far, nothing has materialized.  I think I’m just lazy and need to get started building something.  However, it has been a pretty good few weeks so far.  Simply absorbing new concepts has been invaluable.  The good and bad of my startup is that we are so short-staffed that I have to have my hands in a little bit of everything.  At least I’m hoping that doing so will give me some quick on-the-job training that will help make me more employable in the future.  Here’s to hitting the ground running …

Coming back to coding

So it’s been a tough hill to climb to get back into coding.  Four years out from software engineering is a long time in itself; it probably didn’t help that what I was working on at my previous software engineering job wasn’t state of the art.  It does, however, feel good to be in front of a computer and have the world at my fingertips (so to speak).  If something doesn’t work, I can create it.  Or something like that.  At my old law firm, computers were treated as an afterthought, a technical convenience to a historically paper-driven practice.  That was one particularly irksome attribute of law firms.  Ours in particular bogged our computers down with cumbersome antivirus software, microsoft word plug-ins, security monitoring programs, and the like.  Our internet was blocked.  We couldn’t install new programs onto our laptops.  We used an antiquated and buggy version of internet explorer.  Even java was blocked, despite it being a necessity in certain scenarios to do our job.  This was all to protect us, protect the law firm, and protect clients’ information and work product.  Perhaps these safety measures are a necessary evil to doing the job, but that doesn’t mean they weren’t annoying as f***.

In my trek to return to the software engineering life, I’m starting out by doing things a little differently.  Before going to law school, I skated by in computer science.  I learned best practices as I encountered them in real-life and didn’t make much of an effort to expand my learning beyond what I was directly exposed to.  I’m trying to start out on a new leaf.  I’ve picked up a copy of Effective Java and am trying to understand some best practices before I encounter the problem.  Lots of concepts are confusing, especially in light of my spotty knowledge.  Despite these difficulties, I’m hoping that this will train me to be a better programmer than I was before law school and will hone my skills so that I can do better and more expressive things than before.  I intend to drop in and discuss a few of my coding projects and learnings along the way.  They will probably be too basic for most software engineers, but they’re really more of a chronicle for myself.  I’m selfish like that.  😛

Oh and one more thing:  Apparently, all the cool kids are using github these days.  I didn’t even know what git was 3 months ago when I was first interviewing to come back.  Now I’ve gotten with the times, and you can see some of my amateurish code at my Github page.

Day One

Actually it’s more like day two.  Considering the circumstances, probably more like day 60.  Welcome to my blog.  I am the rocketegg.  Rocketegg is pretty much a meaningless name I came up with years ago when I had to choose a handle to dial into errols internet.  That was a time in my life when the internet was just budding and my interests were focused intently on Diablo and finding a girlfriend.  To give you an idea of my particular brand of uncool, those two things ended up being one solution for me.

Fast forward 12 years or so.  I majored in computer science in undergrad, worked in the software industry for a few years, decided I could “do more” and decided to go to law school.  My reasons for wanting to do so were inarticulate, or maybe just too varied to provide any coherent guidance.  When people asked, I explained that I wanted to broaden my studies, dabble in multiple fields, challenge myself intellectually, and so on.  In truth, the reasons I went to law school were probably more selfish and less honorable than that.  It seemed that all the smart people from my undergrad who had majored in some form of engineering went to a good law school, whereupon graduation they would be handed a fat salary and gobs of prestige, while the remainder of us lived unsatisfying, droll little lives fixing software bugs.  Meanwhile, my dad had raised us with tales of how his father was an important man, a senator in China, who drove a car when probably had never even seen one.  My grandfather, according to my dad, was an honest man, a rarity among politicians whose duty was to call out unethical behavior within his political party.  Naturally, this created enemies along the way who eventually besmirched my grandfather’s reputation and removed him from his position of power.  I loved this tale, romanticized our family being restored to its proper place (albeit in a different country), and law school seemed like the right avenue for the pursuit.  In any case, these two factors worked in conjunction to lead me to law school.

Fast forward another 4 years.  I lived and breathed law school, honestly putting my all into my studies.  It paid off, and I was able to land a job as an associate at one of our country’s top law firms.  It sucked.  There are many things wrong about the law firm model, which I won’t go into.  Suffice it to say that it’s not the right path for me.  Out of my reasons for going to law school, however varied and regardless of the drive it gave me, never included actually wanting to be a lawyer.  It’s perhaps a bit funny to have missed that big point, but at the time my sights were tinted by the allure of the salary and position that our society affords lawyers.  Today is day two of the next step in my career.  I left my law firm last Friday to start (for the second time) my career as a software engineer.  Honestly, I don’t know if I made a mistake.  Perhaps I’m putting too much value on the short term benefits of being a software engineer and too little value on the long term benefits of being a lawyer.  I can’t say.  What I can say is that I’ve been at peace with my decision, and once again I’m genuinely excited about what the future has in store.

That’s the reason for writing this blog.  I don’t know if my story will resonate with anyone.  However, I do know of many unhappy lawyers who would do something else if they could.  My encouragement is to step out, take a leap of faith, and see what destiny has in store.  My parents did that years ago, made mistakes along the way, but by the grace of God landed on their feet.  It’s my hope, and more than I can ask really, to simply do the same.