[英]spring boot - create and destroy bean on the same thread
I'm using a library, that requires me to initialize and deinitialize it on the same thread and if I don't deinitialize it, It will crash JVM.我正在使用一个库,这需要我在同一个线程上初始化和取消初始化它,如果我不取消初始化它,它将使 JVM 崩溃。 The crash on it's own doesn't break anything, just looks ugly, but the error dumps it leaves might quickly fill a lot of space.崩溃本身不会破坏任何东西,只是看起来很丑,但它留下的错误转储可能会很快填满很多空间。
Currently, the code is really simple:目前,代码非常简单:
@Bean
IEngine OCREngine() throws Exception {
return Engine.InitializeEngine(sdkLibraryPath, projectId,
sdkLicensePath, sdkLicensePassword, "", "", false);
}
@PreDestroy
void unloadEngine() throws Exception {
Engine.DeinitializeEngine();
}
I think you need to set the scope of the applicable spring beans to request
.我认为您需要将适用的 spring bean 的范围设置为request
。 This scope will create new bean for each request, which ultimately would correspond to bean creation per thread.这个范围将为每个请求创建新的 bean,这最终将对应于每个线程的 bean 创建。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.