Skip to content
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

Deadlock in REST.java #127

Closed
catsncode opened this issue Mar 20, 2015 · 5 comments
Closed

Deadlock in REST.java #127

catsncode opened this issue Mar 20, 2015 · 5 comments
Assignees
Labels

Comments

@catsncode
Copy link

Hello and thanks so much for the great library. I know you said that it is not thread safe, but do you have any ideas on how I can make it so? It's very strange because I've been using the library for around a year with no problems. Now, all of a sudden I'm getting these deadlocks in REST.java where it is synchronizing on the mutex object. I tried synchronizing the whole method, but no luck. Hopefully someone smarter than myself can give me a little advice.

Thanks!

PS - I'm running my gallery on Tomcat in Linux with Java 7.

@catsncode
Copy link
Author

FYI - I took the synchorized (mutex) lines out of REST.java and it seems to be working fine now. I do a lot of caching in my gallery code, so the REST.java is not called all that much really. I'm sure there was a reason to synchronize that code, but I'm just not sure what it was. I would still like to understand that if anyone else knows. Thanks!

@boncey
Copy link
Owner

boncey commented Mar 23, 2015

Hi, it looks like the DocumentBuilder is not thread-safe hence the synchronization.
That code predates me taking over the library, I'd probably have just instantiated a builder each time. It's slower but simpler and means the class would then be thread-safe.

I don't get much time to work on this project at the moment but suggest that you might want to instantiate a DocumentBuilder within the method if you decide to take out the mutex wrapper.
I don't think there's any other mutable state in that class but I only have a quick look at it.

@catsncode
Copy link
Author

Thanks so much for the advice! I modified the code as you suggested. Is it ok to just have one instance of DocumentBuilderFactory, or should I do a new instance of that each time as well?

@boncey
Copy link
Owner

boncey commented Mar 23, 2015

It looks like it's also not thread-safe so don't set one as a field either, just keep it a local variable.
http://stackoverflow.com/questions/9828254/is-documentbuilderfactory-thread-safe-in-java-5

@catsncode
Copy link
Author

Ok, thanks again for the help!

@boncey boncey added the bug label Aug 2, 2015
@boncey boncey self-assigned this Feb 5, 2019
@boncey boncey closed this as completed in b222e05 Feb 6, 2019
rkipp pushed a commit to rkipp/Flickr4Java that referenced this issue Mar 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants