今天用for循环产生多条线程去缓存里面取数据,数据就是字符串形式的日期,我如果用for循环连续的产生线程去取的话,就会报NumberFormatException,有些时候说 For input string: "",有些时候说 multiple points ,还有些会更怪,类似于For input string: "112011.E112011E44" 这样的log,但当我如果用for循环产生一个线程后,然后睡1毫秒再产生下一个线程的话,又不会产生这样的错误,其实那些缓存着的数据本身格式是没有问题的,因为我打印出来过,而且从我第二种产生for循环的方式也可以看出是没有问题的。不知道是怎么回事
[code="java"]
public class MultiThreadCalendarTest {
static ICalendarService cal = ReferenceDataServiceFactory
.getCalendarService();
public static void main(String[] args) throws Exception {
/**
* Here is used to put the data into the cache.
*/
cal.getNonBusinessDates("DW02", "2011");
/**
* MultiThreads get the data from the cache.
*/
for (int i = 0; i < 2; i++) {
new Thread() {
public void run() {
try {
List<CountryDate> list2 = cal.getNonBusinessDates(
"DW02", "2011");
for (CountryDate date : list2) {
System.out.println(Thread.currentThread().getName()
+ " " + date);
}
} catch (Exception e) {
e.printStackTrace();
}
};
}.start();
// Thread.sleep(1);
}
}
}
[/code]