5 ms·
Hidden Features of Java
- deleted 15y ago[deleted]
- ntkachov 15y agoJava.util.concurrent is one of the most attractive features of java for server programming. ConcurrentHashMap is faster, cleaner and much easier to use than locking every time you need a access a shared HashMap. Not only that but it doesn't lock the entire hash, just a partition of what ever you will be accessing. Also AtomicInt,Float,Long make life easier when dealing with threaded programs.
- jbooth 15y agoDon't forget ExecutorService and the whole concept of sending chunks of work back and forth across synchronizing queues. Best way to write concurrent code in any language IMO, analogous to go's channels/goroutines and erlang's whatever they're called.
- ww520 15y agoJava.util.concurrent.ExecutorService is great. Coupling it with Hazelcast is truly great in creating a dynamic cluster that performs parallel distributed work with ease. One of the pains in setting up server cluster in AWS is the cluster discovery and membership maintenance. Hazelcast does all those automatically.
- theon144 15y ago>closed as not constructive by Robert Harvey♦ Oct 5 '11 at 5:49 >This question is not a good fit to our Q&A format. We expect answers to generally involve facts, references, or specific expertise; this question will likely solicit opinion, debate, arguments, polling, or extended discussion. I appreciate StackOverflow's active moderators, but this question was actually pretty interesting. What harm would it do to let the question open?
- ben0x539 15y agoThe intended use case for stackoverflow is that you have a problem, you google for it, you find a stackoverflow question that covers your problem and click it to find out how to solve it because you know that stackoverflow search results are usually useful for that sort of thing. If they allow other kinds of content, interesting as it may be, it will dilute that and turn stackoverflow into a discussion site or a place where people just post funny anecdotes or assorted programming trivia. That's not inherently bad but it makes it harder to use the site for its intended purpose. (Disclaimer: I have like five karma on stackoverflow and don't necessarily know what I'm talking about.)
- MatthewPhillips 15y agoRecently I asked a question on SO that was closed for not being specific enough. I couldn't recreate the problem for others, I think was the issue, and I was hoping to get some general "try this" answers just to steer me in the right direction. But it seems they don't want that, they want specific questions with exactly 1 correct answer.
- phwd 15y agoMaybe you could not have recreated the problem but you could have indeed described the symptoms and the problem statement. It's not written anywhere in the FAQ but SO places the subliminal message to write better, communicate better and research better. The more you do this, the more you understand your own problem and you will be able to reach your solution. See: http://www.codinghorror.com/blog/2011/02/how-to-write-without-writing.html http://www.codinghorror.com/blog/2011/02/how-to-write-withou... Did some digging and found this http://stackoverflow.com/questions/8449696/project-doesnt-recognize-reference http://stackoverflow.com/questions/8449696/project-doesnt-re... This doesn't look like something to point someone in the right direction. Yes, you are working with proprietary code but you could think of ways to describe what is happening without disclosing information otherwise you are making users play the 20 questions game with your question (as noted by a moderator). A high rep and top contributor to the site (Jon Skeet) was trying to help you but you didn't seem to want to reciprocate with more information. As I said earlier, clear communication is key in SO, don't make users point in the dark. You are wasting their time and yours with the back and forth clarifications.
- jahnu 15y agoThe example in the linked ThreadLocal documentation appears to have a mistake. In getCurrentThreadId it should read return uniqueNum.get(); not return uniqueId.get();
- deleted 15y ago[deleted]
- 6ren 15y agoMy preferred initialization for lists of strings (shorter than the anon class + instance init e.g.) List<String> fruits = Arrays.asList("apple,orange,pear".split(","));
- chrisbroadfoot 15y agoWhy not Arrays.asList("apple", "orange", "pear")
- 6ren 15y agoYou save "" for each extra item, which gets annoying on longer lists.
- eneveu 15y agoI personally prefer Guava's immutable collections: List<String> fruits = ImmutableList.of("apple", "orange", "pear"); It also works for sets and maps: Set<String> fruits = ImmutableSet.of("apple", "orange", "pear"); Map<String, Integer> fruitCounts = ImmutableMap.of("apple", 3, "orange", 2, "pear", 6); http://code.google.com/p/guava-libraries/wiki/ImmutableCollectionsExplained http://code.google.com/p/guava-libraries/wiki/ImmutableColle...
- Ubersoldat 15y agohttp://monocaffe.blogspot.com/2011/10/javas-ghost-jvms.html http://monocaffe.blogspot.com/2011/10/javas-ghost-jvms.html "how does tools like JPS, JConsole or VisualVM know the JVMs running in a system? They simply look in the folder /tmp/hsperfdata_foo where a 32KB data file with the PID as name is created for each JVM." Not a hidden feature of Java, but of Sun's (Oracle) JVM which I'm not sure if happens in other JVMs but it's kind of useful for doing different stuff.