Bugs item #3601279, was opened at 2013-01-17 08:55
Message generated for change (Comment added) made by dnaber
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=655717&aid=3601279&group_id=110216
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: 2.0
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Emmeran Seehuber (eseehuber)
Assigned to: Nobody/Anonymous (nobody)
Summary: Java API: JLanguageTool is not thread safe
Initial Comment:
I`ve just integrated JLanguageTool in a server environment to help the customer
to get there spelling right. So far JLanguageTool is working great - Good work!
But sometimes i get a exceptions in the serverlog (BufferOverFlow,
RuntimeExceptions, ...) from the LanguageTool. To investigate the problem i`ve
created a JUnit Testdriver to reproduce the problems.
The problem is, that at some places JLanguageTool is not threadsafe and uses
unsynchronized static variables, i.e. running new JLanguageTool(...).check() in
parallel will cause all different kind of exceptions.
I did (not yet) investigate future. If LanguageTool would be simple forkable at
githup (Issue 3600257 ...) i would just fork it and try to fix that myself.
For now i will use JLanguageTool only within a
synchronized(JLanguageTool.class) block.
The testdriver is:
import static org.junit.Assert.assertNotNull;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.languagetool.JLanguageTool;
import org.languagetool.Language;
public class TestSpellCheckerFailures {
@Test
public void testSpellCheckerFailure() throws Exception {
System.setProperty("javax.xml.parsers.SAXParserFactory",
"com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
final String txt = " \"Auch wenn Deine kleinen Füße die
Erde nie berührten, sind deine Spuren trotzdem da überall.\"\n"
+ " \n" + "";
final Object syncLock = new Object();
List<Thread> threads = new ArrayList<>();
synchronized (syncLock) {
for (int i = 0; i < 20; i++) {
Runnable r = new Runnable() {
@Override
public void run() {
/*
* Take the lock to ensure that
all threads start at the
* same moment
*/
synchronized (syncLock) {
/*
* Just do something to
ensure the VM does not
* optimize the lock
out.
*/
syncLock.notifyAll();
}
for (int i = 0; i < 100; i++) {
try {
JLanguageTool
tool = new JLanguageTool(Language.GERMANY_GERMAN);
assertNotNull(tool.check(txt));
} catch (Exception e) {
// Set a
breakpoint here to see the exceptions
throw new
RuntimeException(e);
}
}
}
};
Thread t = new Thread(r);
t.start();
threads.add(t);
}
}
for (Thread t : threads)
t.join();
}
}
----------------------------------------------------------------------
Comment By: Daniel Naber (dnaber)
Date: 2013-01-19 05:29
Message:
The issue might be that all Language classes (like Language.GERMAN etc)
look like constants but are in fact complex objects with state. This might
be fixed by the switch to Maven modules I'm just working on.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=655717&aid=3601279&group_id=110216
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_123012
_______________________________________________
Languagetool-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-commits