java - Use of Stanford Parser in Web Service -


i need use stanford parser in web service. sentenceparser loads big object, make sure singleton, in case, thread safe (no according http://nlp.stanford.edu/software/parser-faq.shtml). how else done efficiently? 1 option locking object while being used.

any idea how people @ stanford doing http://nlp.stanford.edu:8080/parser/ ?

if contention not factor, locking (synchronization) 1 option mentioned, , might enough.

if there contentions, however, see 3 general options.

(1) instantiating every time

just instantiate local variable every time perform parsing. local variables trivially safe. instantiation not free of course, may acceptable depending on specific situation.

(2) using threadlocals

if instantiation turns out costly, consider using threadlocals. each thread retain own copy of parser, , parser instance reused on given thread. threadlocals not without problems, however. threadlocals may not garbage collected without being set null or until holding thread goes away. there memory concern if there many of them. second, beware of reuse. if these parsers stateful, need ensure clean , restore initial state subsequent use of threadlocal instance not suffer side effect of previous use.

(3) pooling

pooling in general no longer recommended, if object sizes large need have hard limit on number of instances can allow, using object pool might best option.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -