Answer You need to hold the lock on the object you want to wait on (you can only call it within a synchronized block). Also, calling wait on a Thread is very unusual and probably not what you want. I am not sure what you are trying to do, but could you be confusing wait with sleep? If you want
Clone textview to append it to a ViewGroup
I have a ViewGroup defined in XML with a view inside, at onCreate time I’d like to have a variable of those. I don’t want to go through the hassle of using a listview+adapter cause its clearly overkill as I know the list won’t change since onCreate() This is more or less the code I’d l…
Java implementation of a… JVM?
Some time ago I found the MJVM project. Sadly, this project has been abandoned by it author (I asked Igor via email). I wonder if there is a (continued) open source project of a full implementation of a JVM in Java like this one. By “full”, I mean, not only to emulate mobile devices. Answer The Ji…
Idiomatic way to use for-each loop given an iterator?
When the enhanced for loop (foreach loop) was added to Java, it was made to work with a target of either an array or Iterable. That works great for Collection classes that only implement one type of iteration, and thus have a single iterator() method. But I find myself incredibly frustrated the odd time I wan…
Search for a word in a String
If I am looking for a particular word inside a string, for example, in the string “how are you” I am looking for “are”. Would a regular indexOf() work faster and better or a Regex match() Which of the two methods above is a better way of looking for a string inside another string? Or i…
Converting from Integer, to BigInteger
I was wondering if there was any way to convert a variable of type Integer, to BigInteger. I tried typecasting the Integer variable, but i get an error that says inconvertible type. Answer The method you want is BigInteger#valueOf(long val). E.g., Making a String first is unnecessary and undesired.
Eclipse Java utility project and multiple web apps
If I create a utility project and multiple dynamic web projects within Eclipse and set it up so that dynamic web projects depend on the utility project, I’m guessing that I will have to redeploy all …
Naming conventions for Java methods that return boolean
I like using question mark at the end of method/function names in other languages. Java doesn’t let me do this. As a workaround how else can I name boolean returning methods in Java? Using an is, has, should, can in the front of a method sound okay for some cases. Is there a better way to name such meth…
How to clean up ThreadLocals
Does any one have an example how to do this? Are they handled by the garbage collector? I’m using Tomcat 6. Answer The javadoc says this: “Each thread holds an implicit reference to its copy of a thread-local variable as long as the thread is alive and the ThreadLocal instance is accessible; after…
Difference using @Id and @EmbeddedId for a compound key
I’ve created an entity that uses @Id to point to an @Embeddable compound key. Everything I believe works fine as is. However, after switching @Id to @EmbeddedId everything continues to work fine as far as I can tell. Before: After: Is there a difference between using the @Id and @EmbeddedId annotations …