TurboManage

David Chandler's Journal of Java Web and Mobile Development

  • David M. Chandler


    Web app developer since 1994 and former Developer Advocate with Google 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 241 other followers

  • Sleepless Nights…

    September 2009
    S M T W T F S
    « Mar   Oct »
     12345
    6789101112
    13141516171819
    20212223242526
    27282930  
  • Blog Stats

    • 857,971 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>>()
		{
	
			@Override
			public void onFailure(Throwable caught)
			{
				Window.alert(caught.getLocalizedMessage());
			}
	
			@Override
			public void onSuccess(java.util.List<List> result)
			{	
				// setPrayerLists(result);
				eventBus.fireEvent(new NewListEvent());
			}
		});
	}


	public java.util.List<List> getPrayerLists()
	{
		if (prayerLists == null)
			actionFindLists();
		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!

Advertisements

Sorry, the comment form is closed at this time.

 
%d bloggers like this: