David Chandler's Journal of Java Web and Mobile Development

  • David M. Chandler

    Web app developer since 1994 and Google Cloud Platform Instructor now residing in Colorado. Besides tech, I enjoy landscape photography and share my work at ColoradoPhoto.gallery.

  • Subscribe

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 223 other followers

  • Sleepless Nights…

    September 2009
    S M T W T F S
  • Blog Stats

    • 1,029,897 hits

Method #37 to write an infinite loop

Posted by David Chandler on September 21, 2009

I’ve always thought, had I been keeping track, that it would have been fun to write a book entitled 101 Ways to Write an Infiinite Loop. It seems in every new language or framework I’ve learned, I’ve soon found a way to do it. My latest method involves event handlers in Google Web Toolkit, which I’ve adopted for the RememberOneAnother project.

	public void actionFindLists()
		GWT.log("Calling actionFindLists", null);
		svc.getLists(new AsyncCallback<java.util.List<List>>()
			public void onFailure(Throwable caught)
			public void onSuccess(java.util.List<List> result)
				// setPrayerLists(result);
				eventBus.fireEvent(new NewListEvent());

	public java.util.List<List> getPrayerLists()
		if (prayerLists == null)
		return prayerLists;

The getPrayerLists() method above uses lazy initialization on the prayerLists field to invoke a GWT-RPC service when the view first loads. Without the line that’s commented out, however, the prayerLists field never takes on a non-null value, which causes the service to be called ad infinitum. Moral of the story: when using lazy initialization, don’t forget to initialize the property somewhere!

Sorry, the comment form is closed at this time.

%d bloggers like this: