Fórum

Liferay 6 connecting to a external database works but Stalls entire portal

thumbnail
Brian Scott Schupbach, modificado 12 Anos atrás.

Liferay 6 connecting to a external database works but Stalls entire portal

Expert Postagens: 329 Data de Entrada: 23/10/08 Postagens Recentes
I developed a custom portlet that uses an external database other than liferays. I am able to query/insert/update/delete but the problem is if I try to make a few connections in a short period of time. The portal stalls. No errors appear in the log but the entire portal shuts down. I need to restart tomcat to get it back up. My code is below. Does anyone have any idea what is going wrong? I'm closing everything so I just am not sure what the issue could be. Thanks in advance.

Brian


	public List<account> getAllUniqueAccounts() {
		List<account> list = new ArrayList<account>();
		
		Account a = new Account();
		SessionFactory factory =(SessionFactory) PortalBeanLocatorUtil.locate("liferaySessionFactory");
        Session dbSession = null;
      
		try {
	         
			dbSession = factory.openNewSession(InfrastructureUtil.getDataSource().getConnection());
			String sql = "SELECT distinct AccountNumber, AccountName, Active FROM budget.dbo.Account order by AccountName";
			
			SQLQuery q = dbSession.createSQLQuery(sql);
			//pass query params
			
			if(q != null) {
				List aaList = q.list();
				
				Object obj = null;
				Object row[] = null;
				
				if(aaList != null) {
					for(int i=0;i<aalist.size();i++){ obj="(Object[])aaList.get(i);" row="(Object[])" obj; a="new" account(row); list.add(a); } }catch(exception e){ e.printstacktrace(); dbsession.close(); factory.closesession(dbsession); return list; < code></aalist.size();i++){></account></account></account>
thumbnail
Brian Scott Schupbach, modificado 12 Anos atrás.

RE: Liferay 6 connecting to a external database works but Stalls entire por

Expert Postagens: 329 Data de Entrada: 23/10/08 Postagens Recentes
I've noticed that there are a lot of open connections after running methods like this. Am I not properly closing the connection? What if I did something like this:

 SessionFactory factory =(SessionFactory) PortalBeanLocatorUtil.locate("liferaySessionFactory");
        Session dbSession = null;
      
        try {
             Connection conn =InfrastructureUtil.getDataSource().getConnection();
            dbSession = factory.openNewSession(conn);

etc...

conn.close();

thumbnail
Brian Scott Schupbach, modificado 12 Anos atrás.

RE: Liferay 6 connecting to a external database works but Stalls entire por

Expert Postagens: 329 Data de Entrada: 23/10/08 Postagens Recentes
If anyone has any insights into this issue it would be fantastic to get this resolved.

Thanks,

Brian
thumbnail
Brian Scott Schupbach, modificado 12 Anos atrás.

RE: Liferay 6 connecting to a external database works but Stalls entire por

Expert Postagens: 329 Data de Entrada: 23/10/08 Postagens Recentes
There has to be someone else who has this working correctly...

I'm using tomcat 6 and liferay 6.0.6.

Any help would be GREATLY appreciated.

Thanks,

Brian
thumbnail
Thiago Leão Moreira, modificado 12 Anos atrás.

RE: Liferay 6 connecting to a external database works but Stalls entire por

Liferay Legend Postagens: 1449 Data de Entrada: 10/10/07 Postagens Recentes
One quick advise: use always a finally block to close the resources (connections/sessions).

Connection con = ...
try {
...
} catch (Exception ex) {
} finally {
con.close();
}


This way your clean up routine will be always invoked even if an exception happen.
thumbnail
Brian Scott Schupbach, modificado 12 Anos atrás.

RE: Liferay 6 connecting to a external database works but Stalls entire por

Expert Postagens: 329 Data de Entrada: 23/10/08 Postagens Recentes
Thanks Thiago but I've tried adding in the finally block to close everything and it still stalls. There are no exceptions being thrown.

Brian
thumbnail
Thiago Leão Moreira, modificado 12 Anos atrás.

RE: Liferay 6 connecting to a external database works but Stalls entire por

Liferay Legend Postagens: 1449 Data de Entrada: 10/10/07 Postagens Recentes
Well, the next step is identify the method call that is blocking. My suggestion is to use a debugger or you can fill your code with System.out.println().
thumbnail
Brian Scott Schupbach, modificado 12 Anos atrás.

RE: Liferay 6 connecting to a external database works but Stalls entire por

Expert Postagens: 329 Data de Entrada: 23/10/08 Postagens Recentes
When the method reaches the point where it calls the built in method for connecting to the database is when it stalls. Everything I wrote works fine. To add in println statements to the part that isn't working I am going to have to add them to the Liferay portal source, recompile it, and deploy. Unfortunately, I don't have time for that. I created my own connection pool and am using that now. It is working correctly now because I am no longer using liferay's built in method for connecting to the database. However, I think you guys should be aware that there is something wrong with the Liferay's source in version 6.0.6 that is causing the portal to stall when using this method to connect to the database.

Thanks for looking into this.

Brian
Navnath Gajare, modificado 12 Anos atrás.

RE: Liferay 6 connecting to a external database works but Stalls entire por

New Member Postagens: 2 Data de Entrada: 20/10/11 Postagens Recentes
Hi guys,
can i authenticate user using different database.