Bugs item #3601279, was opened at 2013-01-17 08:55
Message generated for change (Tracker Item Submitted) made by 
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: https://www.google.com/accounts ()
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();
        }
}

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=655717&aid=3601279&group_id=110216

------------------------------------------------------------------------------
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
_______________________________________________
Languagetool-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-commits

Reply via email to