This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Threads and Synchronization and the fly likes Thread Hangs at split method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread Hangs at split method" Watch "Thread Hangs at split method" New topic
Author

Thread Hangs at split method

Kalsi Kore
Greenhorn

Joined: Nov 26, 2010
Posts: 5
Hi,

When i am trying to run the toMinutes(<Time string in HH:MM:SS or HH.MM.SS>) in following code in a loop in my application my thread is hanging the server.

/**
* Finds the separator for time string.
*
* @param timeString time as a string.
* @return separator.
*/
private static String findSeparator(String timeString)
{
String separator = ":";
if (timeString != null)
{
if (timeString.indexOf(separator) == -1)
{
separator = "\.";
}
}
return separator;
}

/**
* Convert the time in HH:MM to time in minutes.
*
* @param timeString time string to be converted (HH:MM:SS).
* @return the time in HH:MM to time in minutes.
*/
public static int toMinutes(String timeString, String separator)
{
Assert.isTrue(validateTimeString(timeString, separator), "Invalid Time String ["
+ timeString + "]");

String[] timeParts = timeString.split(separator);

int hrs = Integer.parseInt(timeParts[0]);
int mins = Integer.parseInt(timeParts[1]);

return (hrs * 60) + mins;
}

/**
* Convert the time in HH:MM to time in minutes.
*
* @param timeString time string to be converted (HH:MM:SS).
* @return the time in HH:MM to time in minutes.
*/
public static int toMinutes(String timeString)
{
int minutes = 0;

if (timeString != null)
{
String separator = findSeparator(timeString);

minutes = toMinutes(timeString, separator);
}
return minutes;
}

below is log.

[11/23/10 16:58:13:232 CET] 00000027 ThreadMonitor W WSVR0605W: Thread "WebContainer : 1" (00000022) has been active for 720641 milliseconds and may be hung. There is/are 1 thread(s) in total in the server that may be hung.
at java.util.regex.Pattern.atom(Pattern.java:1885)
at java.util.regex.Pattern.sequence(Pattern.java:1794 )
at java.util.regex.Pattern.expr(Pattern.java:1687)
at java.util.regex.Pattern.compile(Pattern.java:1397)
at java.util.regex.Pattern.<init>(Pattern.java:1124)
at java.util.regex.Pattern.compile(Pattern.java:817)
at java.lang.String.split(String.java:2103)
at java.lang.String.split(String.java:2145)

Please help.

Thank you.
Kailas
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Can you provide the complete stackTrace?

And Welcome to JavaRanch!! Can you please UseCodeTags to post your source code.


Mohamed Sanaulla | My Blog
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

Also can you tell us what parameters you are passing in as the timeString and seperator?

Sean


I love this place!
Kalsi Kore
Greenhorn

Joined: Nov 26, 2010
Posts: 5
I got only following stack trace from the server.

[11/23/10 16:58:13:232 CET] 00000027 ThreadMonitor W WSVR0605W: Thread "WebContainer : 1" (00000022) has been active for 720641 milliseconds and may be hung. There is/are 1 thread(s) in total in the server that may be hung.
at java.util.regex.Pattern.atom(Pattern.java:1885)
at java.util.regex.Pattern.sequence(Pattern.java:1794)
at java.util.regex.Pattern.expr(Pattern.java:1687)
at java.util.regex.Pattern.compile(Pattern.java:1397)
at java.util.regex.Pattern.<init>(Pattern.java:1124)
at java.util.regex.Pattern.compile(Pattern.java:817)
at java.lang.String.split(String.java:2103)
at java.lang.String.split(String.java:2145)
at com.toyota.tme.asw.service.common.util.WorkshopPlannerUtil.toMinutes(WorkshopPlannerUtil.java:112)
at com.toyota.tme.asw.service.common.util.WorkshopPlannerUtil.toMinutes(WorkshopPlannerUtil.java:134)

Thanks
Kailas Kore
Kalsi Kore
Greenhorn

Joined: Nov 26, 2010
Posts: 5
The timestring passed is any time string in format HH:MM:SS and HH.MM.SS.

The data passed to these methods are validated before splitting the result.

It is sure that there is no invalid data passed to the method.

The separator used are

/**
* Constant for time separator.
*/
public static final String TIME_SEPARATOR = ":";

/**
* Constant for time separator.
*/
public static final String SQL_TIME_SEPARATOR = "\\.";

Thanks
Kailas
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

at com.toyota.tme.asw.service.common.util.WorkshopPlannerUtil.toMinutes(WorkshopPlannerUtil.java:112)


Which is this line in your source code? Also what is the input you are giving? The stack trace looks like some problem with the split (which in turn actually uses Pattern). Did you debug to find out what were the values of separator and timeString?
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Is this the culprit:


Anyways it would not allow you to compile. Might be a typo while copying the code to this post.
Kalsi Kore
Greenhorn

Joined: Nov 26, 2010
Posts: 5
Thread is hanging at below line

String[] timeParts = timeString.split(separator);.

Also this happening in client's environment which is deployed on WAS6.1

Thanks
Kailas
Vlado Zajac
Ranch Hand

Joined: Aug 03, 2004
Posts: 245
There is no reason for Pattern.compile method to hang.

You wrote that it runs in a loop. Isn't the loop infinite?

You can use [.:] as separator (without the need for findSeparator):


Kalsi Kore
Greenhorn

Joined: Nov 26, 2010
Posts: 5
Thanks Vlado.

Initially I also thought that there was an infinite loop. But it is not there.

Really dont know what is the cause thread is hanging.

Kailas
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread Hangs at split method