I have generated code from an openapi yaml file. I'm implementing the handleRequest methods. I need to share the same instance of a "Util" object to reuse it in all the handleRequest calls. Could you please tell me where to store my Util object instance? My Util class is not thread safe, so I should have one instance for each client thread.
How to share a util object which is not thread safe in light-4j handler
40 views Asked by Steve Hu At
1
There are 1 answers
Related Questions in THREAD-LOCAL
- Is exception handling mandatory in MDC.remove() or MDC.put()?
- ThreadLocal context lost with CompletableFuture in Java
- What's the role of using Map to encapsulate ThreadLocal<Map>?
- JDK 21 - Why ThreadLocalRandom's nextInt implement with super.nextInt directly?
- Spring Integration delay along with thread MDC context
- How to propagating context through StructuredTaskScope by ScopedValue, by the way, how about the MDC ThreadContextMap in StructuredTaskScope?
- Check if a function argument value is thread-local
- How do I fix the following issue: Could not write JSON: Failed making field 'java.lang.ThreadLocal#threadLocalHashCode' accessible?
- How does a parent thread in a thread pool obtain data stored in thread local by a child thread
- Linking error with g++ for static inline thread_local variable
- Virtual thread for reading InputStream from HTTP response
- Context-Propagation does not work in @SpringBootTest
- Http Request from Spring Boot 3 Scheduled Jobs
- Java 8 to Java 17 ThreadLocal issue
- Common mutex for shared library dynamic loading and thread_local initialization?
Related Questions in NON-THREAD-SAFE
- How can I make my flask + sqlite3 application threadsafe
- RHEL PHP 8.0 Non-Thread Safe Compilation
- Java class annotated with non thread safe
- unsynchronized read/write of variables may cause data race?
- Running Selenium Webdriver tests with TestNG in parallel does not sent correct data to browser
- How to share a util object which is not thread safe in light-4j handler
- Is this null pointer exception in TreeMap due to concurrent access?
- Making Thread run a Jframe
- Initializing a static Java constant from a non-thread-safe method
Related Questions in LIGHT-4J
- I'm planning to develop an OAuth server in a monolith, can we use light-oauth2 as libraries in our app instead of microservices?
- Add aditional information to json-schema and get it when validate through the networknt json validator
- How to validate array item types with networknt/json-schema-validator?
- How to validate against an OpenAPI schema with $refs using json-schema-validator
- How to validate JSON with schema which contains a reference to another schema?
- Light4J Oauth2 docker-compose error's saying Cannot locate specified Dockerfile
- How to Add Custom Json Schema Validators
- Is there any real light 4j examples for mapping json request to Java POJO objects?
- Is Light-4j similar to the AOP programming?
- Printing query parameters in access log for light-4j application?
- How to create light-4j fatjar for Docker
- How do we integrate access log in logback.xml for light-4j app?
- Light-oauth hazelcast purpose
- Light-OAuth2 Refresh Tokens live forever? (Must be explictly deleted)
- when starting light-oauth2 images, it shows no route handler provider available in service.yml
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
If your class is thread safe, the best place is https://www.networknt.com/concern/service/
If the object is not thread safe then save one object per thread with ThreadLocal. That means one request might be calling two or more instance of util objects when a request is dispatched from an IO thread to a worker thread.
If it's actually a util object can you make it stateless so that it is thread safe? Maybe add an additional context type object for the state if you really need it. Attaching it to the exchange as an attachment could work.