Re: Illegal start of expression error on synchronized block
phillip.s.powell@gmail.com wrote:
<pre>
<code>
synchronized(this) {
// MUST BE WITHIN <init> PRIOR TO INSTANTIATION
try {
SystemFunctionality.add("java.library.path",
JDICGlobals.JDIC_EXECUTABLE_FILE_PATH, "jdic");
} catch (Exception e) {
e.printStackTrace();
}
}
Your example is not complete. Where does this synchronized block appear,
inside a constructor or inside a method?
If inside a constructor, I wonder how synchronization would be necessary.
static /** Go to <a href="http://forums.java.net/jive/thread.jspa?
forumID=72&threadID=15129&messageID=113723">here</a> for more info */
The javadoc tool might have trouble with this comment.
{
BrowserEngineManager engineManager =
BrowserEngineManager.instance();
engineManager.setActiveEngine(BrowserEngineManager.IE);
}
</code>
</pre>
If I put the contents of the synchronized block into the static block,
But you synchronized on "this", which implies that this is not static behavior.
all is fine, however, should I do this? Would it be better to have the
specific Classpath JDIC initialization routine in its own synchronized
block; if so, how do I do it w/o having the "Illegal start of
expression" error?
You should copy and paste the exact error, along with a simple, self-contained
compilable example (SSCCE) that generates it. (Or non-compilable, in your
case, but that generates the exact error of interest.) Paraphrases hide too
much information for us to help.
Normally classpaths are set outside the program; it breaks the proscenium too
much in most cases to manipulate that from inside the code.
Things go into static initialization blocks when they are initialized at class
loading time. Things go into synchronized blocks when multiple threads might
need concurrent access to the data. If neither of those conditions apply, then
you should use neither idiom. They are not interchangeable in any sense.
You likely have not solved your problem simply because you made the error
message disappear.
- Lew