Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread Hangs at split method

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you provide the complete stackTrace?

And Welcome to JavaRanch!! Can you please UseCodeTags to post your source code.
 
Rancher
Posts: 377
Android Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

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

Sean
 
Kalsi Kore
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
It wasn't my idea to go to some crazy nightclub in the middle of nowhere. I just wanted to stay home and cuddle with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic