|
Right, that makes sense. Thanks, fellas.
|
# ? Jul 12, 2012 20:17 |
|
|
# ? Jun 12, 2024 12:46 |
|
MEAT TREAT posted:As you verified with your code the progression was this: InstrumentedHashSet::addAll -> HashSet::addAll -> InstrumentedHashSet::add() x 3 That is certainly correct, but I can't not think about the way C++ is doing things (explicitly allowing for inheritance) and the pains that model causes. There are pros and cons to both models, though personally I prefer the Java one where everything is virtual by default. C++'s one cause way too much pain and suffering for non-disciplined developers (99.999% out there).
|
# ? Jul 13, 2012 03:54 |
I'm having a problem with a jni call crashing my jvm. I'm passing a byte array from java to some C++ code and most of the time it works just fine, but there is one particular byte array I can pass to the native method that causes the jvm to crash. As far as I can tell it's not specific to the length of the byte array, as there are longer arrays I can pass to the native code just fine. I started putting cout's everywhere in the C++ code to figure out where it was crashing, and it doesn't even make it to the first cout, which is the very first line of the method. I know next to nothing about C++ and how to properly debug it though, I've just been treating this native method as a magical black box. I added -Xcheck:jni -verbose:jni to my VM options, doesn't seem to offer me any more clues though. Intellij just spits out "Process finished with exit code 139" when I run my little test program to reproduce the issue. How can I diagnose this thing? edit: I added -XX:ErrorFile=/home/fletcher/whatever.log to my jvm options, but the error file is never created fletcher fucked around with this message at 02:51 on Jul 17, 2012 |
|
# ? Jul 17, 2012 02:07 |
|
Is there any specific idiom for "iterate over a list, run a function per object, return the result of the complete iteration"? In other words, is there a way to generalize all methods like this (which operate inside a list): Java code:
fletcher posted:I added -Xcheck:jni -verbose:jni to my VM options, doesn't seem to offer me any more clues though. Intellij just spits out "Process finished with exit code 139" when I run my little test program to reproduce the issue. How can I diagnose this thing? Exit code 139 is a segmentation fault, if it's using the standard numbers, which I would assume it is.
|
# ? Jul 17, 2012 13:44 |
|
Aleksei Vasiliev posted:Is there any specific idiom for "iterate over a list, run a function per object, return the result of the complete iteration"? You could use this, perhaps. I've never seen anything in the standard library that makes it any easier though.
|
# ? Jul 17, 2012 14:29 |
|
Guava's transform (and presumably the standard transform thing) is to apply a function per object and return a result per object.
|
# ? Jul 17, 2012 14:32 |
|
It's called a "fold" in Haskell / functional languages. There's an article discussing implementing it in Java here. Not sure if it's any use for you, though.
|
# ? Jul 17, 2012 14:41 |
|
The problem with trying to do functional programming on a micro scale in Java is that there's so much boilerplate involved - the main "wins" of better code clarity and all that just don't materialize. I've heard rumblings of something coming in Java 8 alongside better closures, though. In the meantime, some synonyms you might try looking for are things like Aggregate, Fold, or Reduce. I know I've seen a couple of Java libraries with Aggregate operations.
|
# ? Jul 17, 2012 15:16 |
|
Aleksei Vasiliev posted:Guava's transform (and presumably the standard transform thing) is to apply a function per object and return a result per object. Oh whoops you're right I completely misread your post.
|
# ? Jul 17, 2012 15:19 |
|
Aleksei Vasiliev posted:Is there any specific idiom for "iterate over a list, run a function per object, return the result of the complete iteration"? There are other alternatives, but we use LambdaJ a lot.
|
# ? Jul 17, 2012 17:04 |
Aleksei Vasiliev posted:Can you post any of the Java/C++ code you're using? Unfortunately I don't think I can. I tried updating from jdk1.6 u26 to u33, still crashes with no hs_err_pid.log file to be found. I'll see if I can make a reduced test case. fletcher fucked around with this message at 00:48 on Jul 18, 2012 |
|
# ? Jul 18, 2012 00:43 |
The maximum length of the array I can pass before it crashes appears to be controlled by the -Xss jvm parameter (stack size). Does that sound right? How big can I set this value to? Is there a better solution than simply increasing the limit?
fletcher fucked around with this message at 01:29 on Jul 18, 2012 |
|
# ? Jul 18, 2012 01:17 |
Finally got a core dump for that JNI issue I was having, some sort of bug in one of the libraries that the native code uses. Had to do the following on Ubuntu 10.04 to get the core dump: http://chrisjakeway.wordpress.com/2011/12/09/ubuntu-10-04-enable-core-dumps/ On to a new issue! How can I store a java object in memcached that does not implement Serializable?
|
|
# ? Jul 19, 2012 20:44 |
|
fletcher posted:Finally got a core dump for that JNI issue I was having, some sort of bug in one of the libraries that the native code uses. Marshal it yourself. Maybe try Jackson, and store that, or use the binary extensions if you want it to be more compact. And dear god, if nobody's holding a gun to your head, stay away from Serializable on servers. You want uptime and upgradability, not corrupted objects because of version mismatches between objects.
|
# ? Jul 19, 2012 20:55 |
|
You could always try Google Protocol Buffers. It's a wire format but it should work fine.
|
# ? Jul 19, 2012 21:00 |
|
I was pleasantly surprised by GSON's ability to fill fully generic containers inside objects correctly without needing to add extra annotations or getters.
|
# ? Jul 19, 2012 21:42 |
Thanks for the suggestions. We use protobuf for some other stuff. There are tons of different objects from a 3rd party library that I want to cache so I was hoping to avoid writing/maintaining tons of message definitions, need to investigate this though. It's mostly metadata information from a SOAP API, maybe there is something I can do to cache the underlying XML? I wonder if it's expensive to be parsing all the XML over and over though.
|
|
# ? Jul 19, 2012 22:26 |
|
fletcher posted:Thanks for the suggestions. It's CPU bound so if your workload leaves your I/O saturated or memory full, then you should be fine.
|
# ? Jul 19, 2012 22:31 |
|
I am in posted:I was pleasantly surprised by GSON's ability to fill fully generic containers inside objects correctly without needing to add extra annotations or getters. Yeah GSON is great. Just make use of their exclusions, especially if you use Hibernate and have associated mappings. It will cry foul about circular dependencies (even if they're not)
|
# ? Jul 19, 2012 22:50 |
|
Sorry for the lowlevel question, but I'm (hopefully) starting a diploma in IT next spring, and their Introduction to programming class is Java based. Do you guys know any good online resources to give me a good head start? I've worked my way through some of MITs Open-Courseware lectures (it's based on Python, but seem valid to learn some fundementals), but it seem rather silly to go all nuts in a language that I'll "abandon" in 5 months. So, any pointers?
|
# ? Jul 20, 2012 11:34 |
|
The official Java documentation's tutorials are surprisingly good. If you can get through the "Essential Java Classes" module, you'll be laughin' for any first-year Java class.
|
# ? Jul 20, 2012 22:38 |
|
Anybody here have much experience with Gson? I'm trying to use less of a hack method to accomplish something. I have an object with a bunch of fields, one of which is a long. However, the JSON has it as a non-integer, e.g. 1342911054.0. Gson can handle that just fine as I'm not using a custom deserializer for the object. If I am, it fails. Unfortunately I need to use a custom deserializer for what I'm doing. Reduced example: Java code:
Caused by: java.lang.NumberFormatException: For input string: "2911054.0" (Note the number is wrong) I don't know if this is due to an issue/inconsistency with Gson that I should report, or if I'm loving up somewhere.
|
# ? Jul 21, 2012 19:41 |
|
What's happening is that the TypeAdapter that GSON ends up using for your example is ReflectiveTypeAdapter, which is seeing the long value; field in the Example class, then tries to use a parser for Long which then craps out on that number. I'm not sure how you register new TypeAdapters but there is a List <TypeAdapterFactory> factories object inside GSON (Gson.class:120) that it looks for TypeAdapterFactory classes that support your class. It iterates through that List though (Gson.class:352) and once it finds a potential match it plows on ahead, which indicates to me that it'll be hard for you to fix this without using maybe BigDecimal instead of long. I did this based on the current SVN head so if you're using a different version obviously ymmv.
|
# ? Jul 21, 2012 21:12 |
|
Workaround was not actually too difficult once I figured it out, just weird: http://pastebin.com/qsXCvs8w (see lines 33 and 62 on) Just needed to reproduce the default behavior (that workaround class is pretty much just copy-paste). No idea why. Maybe an ordering issue? It seems like I shouldn't need to do this, so I've reported it to Google. Plus I have no idea if that workaround has any side effects. edit: It's because it's using a JsonTreeReader to parse the JSON, instead of a JsonReader. It extends JsonReader and overrides its methods but its implementation doesn't have the fallback double parsing that JsonReader does. Malloc Voidstar fucked around with this message at 01:46 on Jul 22, 2012 |
# ? Jul 21, 2012 22:59 |
What's the right way to tune the MaxPermSize jvm parameter? Just keep increasing it until you no longer see a java.lang.OutOfMemoryError: PermGen space?
|
|
# ? Jul 25, 2012 19:46 |
|
fletcher posted:What's the right way to tune the MaxPermSize jvm parameter? Just keep increasing it until you no longer see a java.lang.OutOfMemoryError: PermGen space? Pretty much. Unless you are running something like Tomcat and doing a lot of redeploying of webapps without restarting Tomcat, then your libraries likely have ClassLoader leaks and no amount of PermGen will be enough. Here's some interesting information on how Tomcat tries to help with these leaks: http://wiki.apache.org/tomcat/MemoryLeakProtection
|
# ? Jul 25, 2012 20:56 |
|
Another way to do it is to literally count up all your class file sizes, including jars. It's a lot of stupid work and you need to be thorough, and that also doesn't include rt.jar or any runtime generated classes (say from Spring proxies or Hibernate proxies).
|
# ? Jul 25, 2012 21:13 |
|
Just wanted to add that WebServices also love to chew through the permgen space when you redeploy them a lot.
|
# ? Jul 25, 2012 22:28 |
|
MEAT TREAT posted:Just wanted to add that WebServices also love to chew through the permgen space when you redeploy them a lot. If this happens to you then you must have a ClassLoader leak, or a configuration where the jvm is not allowed to reclaim objects in permgen.
|
# ? Jul 26, 2012 13:54 |
|
Have any of you guys set up the red5 server/recorder? I'm having a hell of a time at the last step where you have to compile a client app in Eclipse. The problem is I have no understanding of Java Development or deploying applications or Java programming or Eclipse at all. I'm mostly following these instructions: http://stackoverflow.com/a/5746747 The instructions there work for me in that Eclipse doesn't give me any error messages on compile, so I think my application is okay, but it doesn't actually do anything. The only instructions I can find otherwise look crazy complicated, and assume I'm running Apache and compiling everything from scratch: http://red5guide.com/ The server is set up and working, just can't make the red5recorder application work at all; it errors out saying 'can't connect to rtmp://127.0.0.1/(appname)'. I've been on this for at least a day and I'm sure it's because I don't know how to work with Java projects at all. I'm posting this in the faint hope that someone else has set up this project specifically and knows off the top of their head what might be going wrong. Otherwise, I'm going to have to delete everything, and start over with the instructions from red5guide.com even though I don't want to. EDIT-I realize I gave nothing for anyone to go on to actually help, and for that I apologize. This has been frustrating, not because I magically expect Java to work like I want, but rather because I know the problem is my own ignorance. But I have advanced things somewhat and I am now getting actual error messages. The first is: code:
https://groups.google.com/forum/?fromgroups#!topic/red5interest/QVf2h81wvVE He says to: The import org.red5.server.api.IScope cannot be resolved - Update red5 jar or source with latest - Correct location of IScope is org.red5.server.api.scope.IScope, previously it was org.red5.server.api.IScope See, I get this; outdated reference. The thing is, I don't know where to update it. I have the latest Red5.jar (Version 1.0RC2 Created 5/21/2012) that I can find. I've searched for the old reference in-code and it doesn't show up anywhere. I installed the server from a prebuilt binary of 1.0.0-RC2. Scaramouche fucked around with this message at 00:52 on Jul 27, 2012 |
# ? Jul 26, 2012 21:55 |
|
trex eaterofcadrs posted:a configuration where the jvm is not allowed to reclaim objects in permgen. I'm pretty sure it's this, or else GlassFish's class loader has the leak, can't be arsed to find out.
|
# ? Jul 27, 2012 01:12 |
|
an odd problem occurred when I installed some git software within Eclipse and now my entire toolbar looks shrunken and hosed up. it's causing muscle memory movements of my mouse to slow work. After Eclipse restarted, my toolbar looks like this now and not like when I installed it several months ago, stuff is out of order and some things are entirely missing. Is there a way to fix this, I can't seem to find the option to.
|
# ? Jul 27, 2012 06:32 |
|
MEAT TREAT posted:I'm pretty sure it's this, or else GlassFish's class loader has the leak, can't be arsed to find out. If you're using Spring or something else that uses CGLIB (or other proxying mechanisms?), then Glassfish/Tomcat/etc. all seem to have this problem. I think Oracle blamed it on Spring, and Spring blamed it on CGLIB, but nobody ever bothered to fix it.
|
# ? Jul 27, 2012 14:55 |
|
Is there a way to create a file only if it doesn't exist, free of race conditions? I want this behavior: File exists -> throw exception File does not exist -> atomically create the file and increment usage count
|
# ? Jul 27, 2012 20:43 |
|
Sedro posted:Is there a way to create a file only if it doesn't exist, free of race conditions? I want this behavior: I don't know what usage count means in this context, but java.nio.file.Files.createFile(Path path, FileAttribute<?>... attrs) sounds like it would do that. Edit: out = Files.newOutputStream(path, StandardOpenOption.CREATE_NEW); is probably implemented like those, but that's from 1.7 too. Max Facetime fucked around with this message at 02:46 on Jul 28, 2012 |
# ? Jul 27, 2012 21:43 |
|
I am in posted:I don't know what usage count means in this context, but java.nio.file.Files.createFile(Path path, FileAttribute<?>... attrs) sounds like it would do that. That API appears to do what I want, but unfortunately I'm on Java 5 and unable to upgrade. (edit: actually it doesn't do what I want. For some reason I thought it returned a stream.) Edit: I want the standard behavior of the FileOutputStream and RandomAccessFile constructors, except I want an exception if the file already exists. I could use O_EXCL in Unix, FileMode.CreateNew in .NET, etc. I can't find Java support for this anywhere. Sedro fucked around with this message at 23:20 on Jul 27, 2012 |
# ? Jul 27, 2012 22:06 |
|
What do you actually want to do? If you're working with other processes that are co-operating on a locking scheme, use the FileLock class (which maps to whatever file locking operations the OS natively provides, if you're co-operating with other non-Java processes).
|
# ? Jul 28, 2012 01:19 |
|
Let's say that I claimed in an interview that I was a Java wizard, and this set my interviewer off on a mission to ask me increasingly difficult questions about Java to if I was lying. What kinds of questions/topics would I be asked about? Out of all the languages I've used, I've got by far the most experience and am most comfortable in Java, so I figured that it would be best to focus on improving the area I'm good at if I want to get the best job I can when I graduate this Spring. What knowledge separates good, highly-experienced Java-using software engineers from the rest?
|
# ? Jul 28, 2012 15:30 |
|
There are a lot of deep crevices in the Java language that are not covered in most school curriculums. If I was trying to "break" a candidate I might ask about the meaning of the final keyword in various contexts, synchronized for blocks versus methods, or some of the finer details of how nested and anonymous classes work. If that doesn't work, I'd ask some questions about the generics system. In addition to practical matters of semantics there's quite a bit of trivia that could be pulled out- labeled breaks, unicode expansion rules and unsigned types, etc. If you haven't already, I recommend reading Java Puzzlers- at minimum it will help you find holes in your understanding. I'd also expect someone claiming to be skilled with Java to be able to write simple programs without an IDE. If you can't remember how to use Lists and Maps without syntax completion or consulting a Javadoc, I find it hard to believe you've written anything complex.
|
# ? Jul 28, 2012 15:52 |
|
|
# ? Jun 12, 2024 12:46 |
|
Great post Internet Janitor, I just also wanted to add that understanding how the Java serialization framework works is also one of those language features with lots of gotchas there's also the little known Weak References and finally I'd also say that a Java wizard should know how the different garbage collectors work and know how to tune some basic JVM parameters.
Janitor Prime fucked around with this message at 18:38 on Jul 28, 2012 |
# ? Jul 28, 2012 18:30 |