lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael McCandless (JIRA)" <j...@apache.org>
Subject [jira] Commented: (LUCENE-1186) [PATCH] Clear ThreadLocal instances in close()
Date Fri, 27 Feb 2009 21:39:13 GMT

    [ https://issues.apache.org/jira/browse/LUCENE-1186?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12677543#action_12677543
] 

Michael McCandless commented on LUCENE-1186:
--------------------------------------------

bq. could you please explain to me why/when ThreadLocals are used?

Lucene largely uses them to avoid fine-grained synchronization.

EG when you call IndexReader.document(int) we use ThreadLocal to store
a "private" clone for that thread.  Likewise for term vectors, for
caching terms info, and for analyzers to reuse TokenStream instances.


> [PATCH] Clear ThreadLocal instances in close()
> ----------------------------------------------
>
>                 Key: LUCENE-1186
>                 URL: https://issues.apache.org/jira/browse/LUCENE-1186
>             Project: Lucene - Java
>          Issue Type: Improvement
>    Affects Versions: 2.3, 2.3.1, 2.4
>         Environment: any
>            Reporter: Christian Kohlschütter
>            Assignee: Michael McCandless
>            Priority: Minor
>             Fix For: 2.4.1, 2.9
>
>         Attachments: LUCENE-1186-SegmentReader.patch, LUCENE-1186.patch, LUCENE-1186.patch
>
>
> As already found out in LUCENE-436, there seems to be a garbage collection problem with
ThreadLocals at certain constellations, resulting in an OutOfMemoryError.
> The resolution there was to remove the reference to the ThreadLocal value when calling
the close() method of the affected classes (see FieldsReader and TermInfosReader).
> For Java < 5.0, this can effectively be done by calling threadLocal.set(null); for
Java >= 5.0, we would call threadLocal.remove()
> Analogously, this should be done in *any* class which creates ThreadLocal values
> Right now, two classes of the core API make use of ThreadLocals, but do not properly
remove their references to the ThreadLocal value
> 1. org.apache.lucene.index.SegmentReader
> 2. org.apache.lucene.analysis.Analyzer
> For SegmentReader, I have attached a simple patch.
> For Analyzer, there currently is no patch because Analyzer does not provide a close()
method (future to-do?)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message