piątek, 23 grudnia 2022

org.hibernate.AssertionFailure: possible non-threadsafe access to the session

The error is quite clear, but there are many possible causes, so I will just point out one. If you made custom repo implementation in Spring you might have injected EntityManager and then used it for some more advanced operations (normally not available from Spring data). First let's look at valid example:

https://stackoverflow.com/a/26765003/158037

It injects EM as a field and then creates new SimpleJpaRepository, for each call to findAll(). In my first attempt I had created an instance of that class in constructor, to reuse it and ended with that "AssertionFailure: possible non-threadsafe access to the session" error.

wtorek, 31 maja 2022

Async Profiler - quick profiling for any application

Are you tired of setting up Java APM agents, configuring some arcane ENV variables (does "org.jboss.logmanager" ring any bells)? Just try Async Profiler ( https://github.com/jvm-profiling-tools/async-profiler ). It is even trivial to use on your already *running* docker images. For example: 


$ kubectl -n my-namespace cp ./async-profiler-2.8-linux-x64.tar.gz my-pod:/root $ winpty kubectl -n my-namespace exec -it my-pod bash root@my-pod:/# cd /root root@my-pod:~# tar xf async-profiler-2.8-linux-x64.tar.gz root@my-pod:~# cd async-profiler-2.8-linux-x64 root@my-pod:~/async-profiler-2.8-linux-x64# ./profiler.sh -d 1200 -i 10ms -f profile.html 6 Profiling for 1200 seconds Done root@@my-pod:~/async-profiler-2.8-linux-x64# exit kubectl -n my-namespace cp my-pod:/root/async-profiler-2.8-linux-x64/profile.html ./profile.html
Where "-i 10ms" was how often to run sampling and "6" was the pid of java process (you can check for one with `jps` or plain old `ps`). You can view the resulting flame graph (the local "profile.html" file) in any browser.