I dont see how you could optimize that very much more..one thing I would change though, is declaring the boolean as static inside the method. No need for it to be public.