to reproduce this bug, this is the function with @GetMapping
const val ISO8601_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'"
val formatDateFormat = SimpleDateFormat(ISO8601_FORMAT, Locale.CHINA)
@GetMapping("/test")
fun test(): Response<String> {
val isostring = "2023-12-15T07:07:21.069708Z"
// val isostring = "2023-12-14T15:58:04.267158Z"
try {
val result = formatDateFormat.parse(isostring)
return Response.Ok("hello", "ok")
} catch (exception: NumberFormatException) {
logger.error(exception.message ?: "Fuck")
return Response.Ok("hello", "fuck")
} catch (exception: ParseException) {
logger.error(exception.message ?: "Fuck")
return Response.Ok("hello", "shit")
}
}
```
and then use any tools too access the api for many times, such like rust
```rust
use anyhow::Result;
#[tokio::main]
async fn main() -> Result<()> {
let mut futures = Vec::new();
for _ in 1..=1000 {
let future = reqwest::get("http://localhost:8082/api/todolist/test");
futures.push(future);
}
futures::future::join_all(futures).await;
Ok(())
}
there will be an error in the backend
2023-12-15T19:54:56.825+08:00 ERROR 189559 --- [io-8082-exec-75] c.s.w.t.c.CheckConnectionController : For input string: "22022332202233.E2202233E4E.42202233E44"
2023-12-15T19:54:56.825+08:00 ERROR 189559 --- [o-8082-exec-141] c.s.w.t.c.CheckConnectionController : For input string: "22022332202233.E2202233E4E.4"
2023-12-15T19:54:56.826+08:00 ERROR 189559 --- [io-8082-exec-72] c.s.w.t.c.CheckConnectionController : multiple points
2023-12-15T19:54:56.825+08:00 ERROR 189559 --- [o-8082-exec-156] c.s.w.t.c.CheckConnectionController : For input string: "22022332202233.E2202233E4E.4"
2023-12-15T19:54:56.831+08:00 ERROR 189559 --- [o-8082-exec-156] c.s.w.t.c.CheckConnectionController : multiple points
2023-12-15T19:54:56.834+08:00 ERROR 189559 --- [o-8082-exec-186] c.s.w.t.c.CheckConnectionController : For input string: ""
2023-12-15T19:54:56.835+08:00 ERROR 189559 --- [io-8082-exec-54] c.s.w.t.c.CheckConnectionController : multiple points
2023-12-15T19:54:56.837+08:00 ERROR 189559 --- [nio-8082-exec-8] c.s.w.t.c.CheckConnectionController : multiple points
2023-12-15T19:54:56.838+08:00 ERROR 189559 --- [o-8082-exec-120] c.s.w.t.c.CheckConnectionController : multiple points
2023-12-15T19:54:56.838+08:00 ERROR 189559 --- [io-8082-exec-56] c.s.w.t.c.CheckConnectionController : multiple points
2023-12-15T19:54:56.825+08:00 ERROR 189559 --- [o-8082-exec-176] c.s.w.t.c.CheckConnectionController : For input string: "22022332202233.E2202233E4E.42202233E4"
2023-12-15T19:54:56.840+08:00 ERROR 189559 --- [io-8082-exec-54] c.s.w.t.c.CheckConnectionController : multiple points
2023-12-15T19:54:56.841+08:00 ERROR 189559 --- [o-8082-exec-176] c.s.w.t.c.CheckConnectionController : multiple points
2023-12-15T19:54:56.841+08:00 ERROR 189559 --- [o-8082-exec-120] c.s.w.t.c.CheckConnectionController : For input string: ""
2023-12-15T19:54:56.842+08:00 ERROR 189559 --- [o-8082-exec-120] c.s.w.t.c.CheckConnectionController : multiple points
2023-12-15T19:54:56.826+08:00 ERROR 189559 --- [o-8082-exec-195] c.s.w.t.c.CheckConnectionController : multiple points
2023-12-15T19:54:56.842+08:00 ERROR 189559 --- [io-8082-exec-58] c.s.w.t.c.CheckConnectionController : For input string: ""
2023-12-15T19:54:56.843+08:00 ERROR 189559 --- [io-8082-exec-23] c.s.w.t.c.CheckConnectionController : multiple points
2023-12-15T19:54:56.844+08:00 ERROR 189559 --- [o-8082-exec-120] c.s.w.t.c.CheckConnectionController : For input string: "2032233.E20322334E20322334E4"
2023-12-15T19:54:56.831+08:00 ERROR 189559 --- [io-8082-exec-72] c.s.w.t.c.CheckConnectionController : multiple points
does the multithread matter ? how can I fix this bug ?
ps: I use springboot 3.1.3, kotlin
Comment From: philwebb
I have edited your comment to remove the profanity. We prefer to keep this issue tracker family friendly.
I don't believe this is a Spring Boot bug. The SimpleDateFormat class is not thread safe and I think that might be causing your bug. You could switch to java.time.format.DateTimeFormatter which is thread safe or create a new SimpleDateFormat instance in the @GetMapping method.
If you have any further questions, please raise them on stackoverflow.com. We prefer to keep this issue tracker only for bugs and enhancements.
Comment From: nesteiner
sorry to bother you, thak you anyway