-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception in multi-thread application #167
Comments
Tough one... Do you happen to have a stack trace and a bit more code context (or repo case)? As an educated guess: maybe two threads write to the same internal Hibernate data structure. A solution could be to separate the (Hibernate-managed) data structures per thread. |
I doubt that Hibernate is thread-safe - and also that Uby API is. I would recommend not sharing a Uby context across threads or in a webapp, not sharing a Uby context across page requests. |
How are you dealing with sessions? Hibernate sessions are not thread-safe, every thread should have its own session. |
Afair the Uby API wraps the hibernate session and keeps it. So if a single instance of the Uby API is shared in an application, so is the Hibernate session. |
That probably would lead to problems, not to mention transaction isolation issues. |
At the moment I am not able to share to you the whole stacktrace (I will do it when I go home). What I can say to you at the moment is that I use the UBY API only for reading information. But, I have noticed that this does not give me any guarantees due to Hibernate's lazy-loading. Analyzing the stacktrace that I got, I have found that the reason of the error (apparently) is that I use an HashSet in order to collect some _SemanticPredicate_s that I need in my algorithm. As you know, when you use an HashSet, the elements in the container should implement equals and hashCode. In this case, something pretty weird happens when those methods are invoked and an exception is raised in this situation. Any ideas about this specific behaviour? Changing the data structure to a List, seems to solve this error. It is a nice trick but I want to know more about this. Thank you to all for your help. I really appreciate it. EDIT: Here there is the code that I use:
I hope that someone can help me with this. After some extensive tests I've found that the List trick doesn't work. EDIT-2:
|
I have solved my problem. Apparently your implementation of the class Uby is not well suited for a multi thread application. I am not able to create multiple Uby instances because the SessionFactory cannot be instanciated multiple times (according to this StackOverflow question). For this reason, I have implemented a custom Uby class in this way:
I have implemented some custom features in my fork, so if you want I can make a pull request in order to merge my results. I hope that could help you to add this feature to this really useful library. Thank you again for your time. Alessandro |
Thanks for sharing your solution! I keep this issue open, such that this or a similar solution can be integrated in the master branch. |
If you need any help, don't hesitate to contact me. I will be very happy to contribute. |
Hello,
I am using your library with the Hibernate support and it works great. At the moment I have started to use an improved implementation of my algorithm that uses multiple threads. When the number of threads starts to grow, I receive strange errors like this one:
I use your API only to read resources from the supported lexicons in UBY. The data structures that I use have a restricted visibility so only a single thread can access them. In this case, the database is the only shared resource of the whole program.
Any idea about this error? Can you give me some suggestions?
Thank you in advance.
Alessandro
The text was updated successfully, but these errors were encountered: