You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by wfroud <wf...@gmail.com> on 2008/06/05 17:32:33 UTC

ListChoice Crashing on 13th Load

Hi,

I've been having trouble getting my app to run for any reasonable period of
time without crashing. I've laid out a basic page that contains a 

ListChoice component, after loading this page 13 times (when I have more
components it's far less) it just hangs indefinitely.

I'm sure the problem is something to do with either storing heavy objects in
memory or a serialization issue (from all that I have read) but I 

can't work out why. 

I'm using Wicket version 1.2.6 in development mode with Java 5.

Here is my code:

public class Operations extends WebPage {

	private String selection;
		
	@SpringBean
	private ICategoryDao categoryDao;
	
	public void setCategoryDao(ICategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

	...

	MyCategory catModel = new MyCategory();

	ListChoice categories = new ListChoice(
		"categories",
		new PropertyModel(catModel, "category"),
		new LoadableDetachableModel() {
			@Override
			protected Object load() {
				return categoryDao.getAllCategories();
			}
		}, 
		new ChoiceRenderer("category", "categoryId"),
		5); 
	    
	add(categories);

	...
}


public class MyCategory { 

	private Category category;
	
	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

}	

public class CategoryDao implements ICategoryDao {
	
	@SpringBean
	private DataSource dataSource;
	
	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	} 
	
	private Connection getConnection() {
		return DataSourceUtils.getConnection(dataSource);
	}
	
	public List getAllCategories() {

		List results = new ArrayList();
		
		try {
			PreparedStatement st = getConnection()
				.prepareStatement("SELECT Category_ID, Category FROM Category");
			try {
				ResultSet rs = st.executeQuery();
				while (rs.next()) {
					results.add(
						new Category(rs.getInt("Category_ID"), rs.getString("Category"))
					);
				}
				return results;
			} finally {
				st.close();
			}
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}
}

public class Category implements Serializable {
	private int categoryId;
	private String category;

	public Category(int categoryId, String category) {
		this.categoryId = categoryId;
		this.category = category;
	}
	
	public String getCategory() {
		return category;
	}
	
	public void setCategory(String category) {
		this.category = category;
	}
	
	public int getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(int categoryId) {
		this.categoryId = categoryId;
	}
}

Please could you provide some code snippets or comments if you know why this
might be crashing.

Thanks very much for your time, much appreciated.

Regards, 

Will
-- 
View this message in context: http://www.nabble.com/ListChoice-Crashing-on-13th-Load-tp17672729p17672729.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: ListChoice Crashing on 13th Load

Posted by Michael Allan <mi...@zelea.com>.
wfroud wrote:
> Thanks for the help... I have switched from the JDBC code to using
> the JDBCTemplate, my new DAO class is as follows...  And it works
> perfectly.

I'd hang judgement, till you test it on a Friday. :^O
-- 
Michael Allan


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: ListChoice Crashing on 13th Load

Posted by wfroud <wf...@gmail.com>.
Thanks for the help, for anyone that reads this message stream I have
switched from the JDBC code to using the JDBCTemplate, my new DAO class is
as follows:

public class CategoryDao implements ICategoryDao {

	private JdbcTemplate jt;	
	
	public void setDataSource(DataSource dataSource) {
		this.jt = new JdbcTemplate(dataSource);
	} 
	
	public List getAllCategories() {
	
		List results = this.jt.query(
			"SELECT Category_ID, Category FROM Category",
			new RowMapper() {
				public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
					return new Category(rs.getInt("Category_ID"),
rs.getString("Category"));
				}
			});

		return results;
	}
}

And it works perfectly.
-- 
View this message in context: http://www.nabble.com/ListChoice-Crashing-on-13th-Load-tp17672729p17687430.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: ListChoice Crashing on 13th Load

Posted by Eelco Hillenius <ee...@gmail.com>.
On Thu, Jun 5, 2008 at 8:44 AM, John Krasnay <jo...@krasnay.ca> wrote:
> You are not closing your JDBC connections, and are therefore you are
> running out of connections in your connection pool.

Yep, probably something like that.

> I would STRONGLY advise against using raw JDBC. You have no idea how
> difficult it is to correctly clean up after JDBC. At the very least look
> into Spring's JdbcTemplate class, and if you're doing serious work
> invest in learning Hibernate.

Or consider looking at iBatis (http://ibatis.apache.org/), which let's
you stay closer to JDBC, but has a bunch of nice code-saving features,
and will probably handle stuff like this better as well.

Eelco

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: ListChoice Crashing on 13th Load

Posted by John Krasnay <jo...@krasnay.ca>.
You are not closing your JDBC connections, and are therefore you are
running out of connections in your connection pool.

I would STRONGLY advise against using raw JDBC. You have no idea how
difficult it is to correctly clean up after JDBC. At the very least look
into Spring's JdbcTemplate class, and if you're doing serious work
invest in learning Hibernate.

jk

On Thu, Jun 05, 2008 at 08:32:33AM -0700, wfroud wrote:
> 
> Hi,
> 
> I've been having trouble getting my app to run for any reasonable period of
> time without crashing. I've laid out a basic page that contains a 
> 
> ListChoice component, after loading this page 13 times (when I have more
> components it's far less) it just hangs indefinitely.
> 
> I'm sure the problem is something to do with either storing heavy objects in
> memory or a serialization issue (from all that I have read) but I 
> 
> can't work out why. 
> 
> I'm using Wicket version 1.2.6 in development mode with Java 5.
> 
> Here is my code:
> 
> public class Operations extends WebPage {
> 
> 	private String selection;
> 		
> 	@SpringBean
> 	private ICategoryDao categoryDao;
> 	
> 	public void setCategoryDao(ICategoryDao categoryDao) {
> 		this.categoryDao = categoryDao;
> 	}
> 
> 	...
> 
> 	MyCategory catModel = new MyCategory();
> 
> 	ListChoice categories = new ListChoice(
> 		"categories",
> 		new PropertyModel(catModel, "category"),
> 		new LoadableDetachableModel() {
> 			@Override
> 			protected Object load() {
> 				return categoryDao.getAllCategories();
> 			}
> 		}, 
> 		new ChoiceRenderer("category", "categoryId"),
> 		5); 
> 	    
> 	add(categories);
> 
> 	...
> }
> 
> 
> public class MyCategory { 
> 
> 	private Category category;
> 	
> 	public Category getCategory() {
> 		return category;
> 	}
> 
> 	public void setCategory(Category category) {
> 		this.category = category;
> 	}
> 
> }	
> 
> public class CategoryDao implements ICategoryDao {
> 	
> 	@SpringBean
> 	private DataSource dataSource;
> 	
> 	public void setDataSource(DataSource dataSource) {
> 		this.dataSource = dataSource;
> 	} 
> 	
> 	private Connection getConnection() {
> 		return DataSourceUtils.getConnection(dataSource);
> 	}
> 	
> 	public List getAllCategories() {
> 
> 		List results = new ArrayList();
> 		
> 		try {
> 			PreparedStatement st = getConnection()
> 				.prepareStatement("SELECT Category_ID, Category FROM Category");
> 			try {
> 				ResultSet rs = st.executeQuery();
> 				while (rs.next()) {
> 					results.add(
> 						new Category(rs.getInt("Category_ID"), rs.getString("Category"))
> 					);
> 				}
> 				return results;
> 			} finally {
> 				st.close();
> 			}
> 		} catch (SQLException e) {
> 			throw new RuntimeException(e);
> 		}
> 	}
> }
> 
> public class Category implements Serializable {
> 	private int categoryId;
> 	private String category;
> 
> 	public Category(int categoryId, String category) {
> 		this.categoryId = categoryId;
> 		this.category = category;
> 	}
> 	
> 	public String getCategory() {
> 		return category;
> 	}
> 	
> 	public void setCategory(String category) {
> 		this.category = category;
> 	}
> 	
> 	public int getCategoryId() {
> 		return categoryId;
> 	}
> 
> 	public void setCategoryId(int categoryId) {
> 		this.categoryId = categoryId;
> 	}
> }
> 
> Please could you provide some code snippets or comments if you know why this
> might be crashing.
> 
> Thanks very much for your time, much appreciated.
> 
> Regards, 
> 
> Will
> -- 
> View this message in context: http://www.nabble.com/ListChoice-Crashing-on-13th-Load-tp17672729p17672729.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: ListChoice Crashing on 13th Load

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Thu, 05 Jun 2008, wfroud wrote:
> I've been having trouble getting my app to run for any reasonable period of
> time without crashing. I've laid out a basic page that contains a 
> 
> ListChoice component, after loading this page 13 times (when I have more
> components it's far less) it just hangs indefinitely.

Hello,

Is your application crashing or hanging? If hanging, take a
couple of thread dumps during the hang to see where the
threads are stuck.

The advice about JDBC applies of course.

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org