File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Glassfish and the fly likes Glassfish 4.0 unstable after redeployment with startup, shut down and connection pool problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Glassfish
Bookmark "Glassfish 4.0 unstable after redeployment with startup, shut down and connection pool problems" Watch "Glassfish 4.0 unstable after redeployment with startup, shut down and connection pool problems" New topic
Author

Glassfish 4.0 unstable after redeployment with startup, shut down and connection pool problems

Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 162

I'm new to GF so forgive the 'rookie' question please. Sorry to say my experience with GLassfish is going from bad to worse but I"m hoping to figure out exactly where I'm going wrong.

I'm using GF4.0 with Netbeans 8.0 in Windows Server 2008 R2 64-bit. I try to build a simple JDBC j_security_check user admin applocation to the test the security. I'm having a number of problems. Firstly the server hangs if I try to re-deploy the application and I have to force it to close using a jps command (jdk1.7.0_25\bin>taskkill /pid 5756 /F). After I do this it looks like the GF management becomes out of synch in Netbeans. The start and stop commands from the Services tab in Netbeans no longer work and the log messages get delayed so I'm no longer able to monitor application deployment properly.

I tried uninstalling and re-installing the GF and NB several times, but I keep running into the same problem. I also tried downgrading to GF 3 but this did not fix the problem either. Some possible causes I can think of are:

1) Some Configuration setting to allocate the right amount of RAM is set incorrectly / I need to allocate more memory at the start of the server
2) Setting the logging levels to FINE on more than one module causes the server to slow down
3) A connection pool is not being closed and is either causing a memory lack or slowing down server operations

I"ve searched online for possible causes, but didn't find any conclusive information. My questions are:

1) Is it better to use GF utiliities asdmin or the admin console for all server operations and not rely on the IDE tools?
2) Are there any known issues which make Glassfish unstable when used with Netbeans that anybody has come across?
3) Are there any known issues (or special settings that are not covered in the Glassfish documentation) with creating connection pools that cause Glassfish to become unstable like this?

I'm sorrry if my questions seem general. I've never experienced anything like this where the server just stops functioning when trying to create a connection pool and deploying a simple login application. At this point I'm looking for any experience or guidance with this type of problem. I'm also trying to decide whether to continue using GF in a production enviironment or return to Tomcat or use another app server.

I'd be happy to provide any further information but my stack traces from the server log are quite long and seem to contain generic server startup and initialization information, like:



When i I do finally 'force' the server to stop and restart and run my application again i get:



and the following warning:


Has anybody come across the above error or experienced Glassfish becoming unstable after re-deployment? I posted a similar problem GlassFish JSF Problem, but don't seem to have an answer for that either yet.
Thanks in advance,

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2416
    
    7

Hello Jay

First I haven't used GF4 or Netbeans 8.0 but I personally don't rely on Netbeans to start/stop GF and deploy/redeploy applications. I simply have a batch file to start/stop GF and use NB to build the war or ear file then go to the admin console to deploy apps.

Make sure that "auto-deploy" option is turned off, otherwise NB will attempt to deploy it for you when you save or something.

1) Some Configuration setting to allocate the right amount of RAM is set incorrectly / I need to allocate more memory at the start of the server

From my experience at least on GF3.x, the default memory allocation is like 512M really small and for normal operations, this shouldn't cause problems. I don't know how many apps you have deployed but the memory setting is for the whole server. I don't know if there is such setting for each individual app.

2) Setting the logging levels to FINE on more than one module causes the server to slow down

Possibly because there is more disk I/O. Thinking about it is "FINE" necessary? If you are setting to FINE because of debugging purposes, I suggest you use System.out to console or output the variable on the actual web page (if you don't want to look at the console logs)

3) A connection pool is not being closed and is either causing a memory lack or slowing down server operations

This clearly problematic with your coding. If the connection is not closed, such connection will not return to the pool making the application slower and eventually either there is no more connections to use or OutOfMemoryError. If your are using JDK7 do use the try-with-resource statement to ensure the connections are "auto-closed". If JDK6, have those finally blocks.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 162

Thanks a lot for your comments. I'm going tjroigh themm in detail but I have some immediate questions and additional issues to raise which might help resolve this problem. I use NB to manage Glassfish partly because it's very convenient to see the GF server log in the NB console. Still i'm going to try deploying war files from the GD admin console. I'm still concerned about why GF would slow down so badly after re-deploying the application.



What I find really odd is that all the above errors are duplicated (repeated) at least 3 times after I enter the username and password values in the login form when running the application. Repeating processes also hapen when I'm starting the server and I get:



Is it normal behavior for processes (such as logging into the admin user) to be repeated?
Is there any reason why the 'cannot find name to unbind' error is repeated? Is it just because the server is making several attempts to find this?
Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 162

Another update regarding the connection pool. I can ping the pool succesfully but when I try to flush the pool from the admin console I get:

Flush Connection Pool failed for securityConnectionPool. Flush Connection Pool did not happen as pool - securityConnectionPool is not initialized. Please check the server.log for more details.


This tells me the pool is not even being read by the application so maybe the problem has nothing to do with closing the connection?
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2416
    
    7

Jay Tai wrote:Another update regarding the connection pool. I can ping the pool succesfully but when I try to flush the pool from the admin console I get:

Flush Connection Pool failed for securityConnectionPool. Flush Connection Pool did not happen as pool - securityConnectionPool is not initialized. Please check the server.log for more details.


This tells me the pool is not even being read by the application so maybe the problem has nothing to do with closing the connection?


I don't know if flushing the connection pool is the way to go but just curious what DB are you using? If MySQL then according to stackoverflow thread here, there was an issue, yet can't find what GF version it is referring to.

Also are you getting this only during redeploy? If you undeploy and deploy again, which this happen?
Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 162

Thanks. I don't know what the right way to go is at this point. If I manually undeploy and re-deploy then the server hangs while re-deploying and stays like that for a long time. I'm usually forced to kill the task through jps. I then re-installed GF but the same issue happens. The stackoverflow issue you provided probably refers to Glassfish 3 but I'm noticing a similar issue for GF4. Hope that answers your question and I'm happy to provide further details or stack trace to help resolve this. I'm concerned that such a simple thing as a j_security_check could be so complicated. Either GF has serious bugs or I'm going seriously wrong with the configuration. Looks like my problem could be related to the fact that my database / connection pool is not being read.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2416
    
    7

Thanks for the update. If you are to reinstall GF, try not to install in a path with spaces (eg "Program Files" on Windows). Path with spaces tends to cause problems to server's classpath and stuff.

Since you are using that j_security_check thing, is your web.xml configured properly to use "FORM" authentication?

One test you can do is forget the DB and just test the username/password by hard-coding. If this goes smooth then it's just the persistent unit.
Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 162

Thanks for the suggestions. I set up a new application using the file realm and it works fine. Next I will try to reinstal to a location that doesn't contain spaces and test the JDBC again. At this point it might be worth showing you the config files in my JDBC app:

web.xml


sun-web.xml


sun-resources


login.html

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2416
    
    7

I would also suggest you create the jdbc connection directly in GF.

By putting the resource file in your war file I think would try to redeploy this connection every time. Hence it may try to flush the pool etc.

Resources ideally suppose to be deployed once.
Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 162

Will do. Thanks
Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 162

OK I tried to create JDBC login as you suggested, creating the connection pool, jdbc resource and realm from the GF admin console. I still get the following trace:




Could the doPassWordLoginFails error be resulting from me using NONE as the PW encryption algorithm?
How can I debug the persistence in more detail to identify what is actually happening with the DB operations?

web.xml


sun-web.xml


Connection Pool Settings:

Pool Name: secConPool
Resource Type: com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
URL: jdbc:mysql://localhost:3306/jdbcrealm
Url: jdbc:mysql://localhost:3306/jdbcrealm
DBName: jdbcrealm
ServerName: localhost
Username: root
PW: ********

msecurityrealm



mySql script:




K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2416
    
    7

I see don't know why. I will try to simulate your scenario on GF3 with and without JSF and see if I get same result.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2416
    
    7

OK did some testing on GF3 and guess what I can't get it to work. I got:

No stack trace whatsoever. May be it's my logging level

This is what I did:
Created new project with nothing, have login and error html pages and html in admin folder
web.xml looks like:

glassfish-web.xml (or sun-web.xml) has the following added:


DB side, 3 tables:
Table user (id, userid, password) = 1, "johndoe", MD5("john")
Table group (id, name, description) = 1, "admin", NULL
Table user_group (userid, groupid) FK to user.userid and group.id columns respectively = "johndoe", 1

In glassfish
create connection pool and jdbc resource (jdbc/soup) pointing to database
create security realm:


Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 162

Very interesting and has similarities to my trace. I set my log levels to finest for the javax security module. I also remember there is a way to debug the login context by adding a JVM property in the admin console or as a start option to Netbeans. Could this be a persistence bug in Glassfish? Does GF accept NONE as a password encryption algorithm in the security realm settings?
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2416
    
    7

Jay Tai wrote:Does GF accept NONE as a password encryption algorithm in the security realm settings?


If this is the case, the password stored in DB would be plain text I assume. Because I read articles the digest algorithm is "none" and didn't mention about the password digest algorithm which GF say "should have something". Also if you leave digest algorithm blank it gets the default (eg SHA)

I will try your suggestion and debug some more.
Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 162

Well in GF4 it won't let you set up the realm without specifying the algorithm so you can't leave it blank. From what I read GF does accept NONE as an algorithm and of course this is only recommended for testing. So it shouldn't be a problem to store passwords in clear text at all although I've never managed to get it working. Would be interested to know how you get on.
Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 162

Ok I finally made a breakthrough and got a simple login app on GF4 to work. I created two tables. The first is users with two columns - username and password. The second is groups, also two columns - groups_un and groupname. The trick to making this work and avoiding a security exception is to fill in BOTH the PW encryption algorithm AND the Digest Algorithm when creating the realm. Before I left the Digest Algorithm blank as it was not a mandatory field. Since I wasn't using Sha-256 encryption, the default Digest encryption didn't work. This time I put NONE in both fields and it worked. My next question is if I'm going to use Sha-256 encryption that would be the value I put in the PW encryption field when creating the realm - right? Secondly, what should I put as the Digest Algorithm value? Thanks!
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2416
    
    7

I see you got it to work.

About the algorithm, I believe the password digest is for the algorithm stored in DB.

I did remember when I first created my realm, I put in both algorithms ... but it didn't work for me.
Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 162

Yes, getting the clear text to work was successful as long as you enter 'NONE' for the Digest algorithm value. Now the question is how to get this working using SHA-256 encryption? Maybe I should make a separate post about this. Specifically I'd like to know what value I should enter for the Password Encryption Algorithm when creating the realm. Should it be 'AES'? I'm also guessing that the Digest Algorithm field should be left blank (in which case it defaults to Sha-256). Thanks,
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Glassfish 4.0 unstable after redeployment with startup, shut down and connection pool problems