Menu

#54 Make configuration variables thread safe

open
nobody
None
5
2007-03-04
2007-03-03
CapnNemo
No

There are various static fields that are used as configuration items to control the behaviour of the parser.

org.htmlparser.lexer.Lexer.STRICT_REMARKS
org.htmlparser.scanners.ScriptScanner.STRICT
org.htmlparser.scanners.ScriptDecoder.LAST_STATE
org.htmlparser.util.Translate.DECODE_LINE_BY_LINE
org.htmlparser.util.Translate.ENCODE_HEXADECIMAL

As they are static, this means that it is not possible to use different settings in different threads.

For example, it is not currently possible to use a STRICT scanner and a non-STRICT scanner in different threads (except perhaps by using different classloaders ...).

Discussion

  • CapnNemo

    CapnNemo - 2007-03-03
    • priority: 5 --> 7
     
  • Derrick Oswald

    Derrick Oswald - 2007-03-04
    • milestone: 643431 -->
    • priority: 7 --> 5
    • summary: Configuration variables not Thread safe --> Make configuration variables thread safe
     
  • Derrick Oswald

    Derrick Oswald - 2007-03-04

    Logged In: YES
    user_id=605407
    Originator: NO

    Not really a bug.
    Change to Request For Enhancement.

     
  • CapnNemo

    CapnNemo - 2007-03-07

    Logged In: YES
    user_id=1716708
    Originator: YES

    In order to use anything but the default configuration safely, all threads must use and set the same value.

    If thread A sets STRICT=false, and thread B does not, then there is no guarantee that thread B will see the same value of STRICT throughout its lifetime. The Java memory model allows threads to cache values locally, so thread A may use its own copy of STRICT initially but then write it to main memory partway through thread B's operation.

    It is admittedly unlikely, but it is permitted by the memory model as far as I understand it.

     

Log in to post a comment.