On Nov 4, 2010, at 22:26, Atsuo Ishimoto <ishim...@gembook.org> wrote:

Hello,

I ran into a problem when I tried to use jcc for Apache Tika 0.7.
I can construct org.apache.tika.parser.AutoDetectParser instance in
the main thread, but cannot in the child thread.
From following code,

import threading, infopilejavalib
infopilejavalib.initVM()

def f():
   infopilejavalib.getVMEnv().attachCurrentThread()
   print infopilejavalib.AutoDetectParser() # fails

print infopilejavalib.AutoDetectParser() # succeeds
threading.Thread(target=f).start()

I got

org.apache.tika.parser.autodetectpar...@53fb57
Exception in thread Thread-1:
Traceback (most recent call last):
 File "c:\python26\lib\threading.py", line 525, in __bootstrap_inner
   self.run()
 File "c:\python26\lib\threading.py", line 477, in run
   self.__target(*self.__args, **self.__kwargs)
 File "wk\a.py", line 47, in f
   print infopilejavalib.AutoDetectParser() # fails
JavaError: sun.misc.ServiceConfigurationError:
org.apache.tika.parser.Parser: Provider
org.apache.tika.parser.asm.ClassParser not found
   Java stacktrace:
sun.misc.ServiceConfigurationError: org.apache.tika.parser.Parser:
Provider org.apache.tika.parser.asm.ClassParser not found
       at sun.misc.Service.fail(Unknown Source)
       at sun.misc.Service.access$000(Unknown Source)
       at sun.misc.Service$LazyIterator.next(Unknown Source)
at org.apache.tika.config.TikaConfig.<init>(TikaConfig.java: 147) at org.apache.tika.config.TikaConfig.getDefaultConfig (TikaConfig.java:207) at org.apache.tika.parser.AutoDetectParser.<init> (AutoDetectParser.java:46)

Investigating further, I found threads created by JNI don't have class loader.

def f():
   infopilejavalib.getVMEnv().attachCurrentThread()
   thread = infopilejavalib.Thread.currentThread()
   clsloader = thread.getContextClassLoader()
   print clsloader # prints None

threading.Thread(target=f).start()

This script print None as the context class loader.
I can call thread.setContextClassLoader() manually, but it might be
useful if jcc's attachCurrentThread() does it.

Thoughts?

What is a context class loader ?
If calling setContextClassLoader() solves the problem then this could be done by passing the context class loader as a new optional parameter to attachCurrentThread(). Where does this class loader come from and why isn't it set in the first place ? What version of Java is this and whose VM ?

If you'd like to propose a patch that would be welcome.

Andi..


--
Atsuo Ishimoto
Mail: ishim...@gembook.org
Blog: http://d.hatena.ne.jp/atsuoishimoto/
Twitter: atsuoishimoto

Reply via email to