|
Mill Town posted:Sounds cool, but I see it takes SQL commands as raw text. Is there a sanitize function available? I can't find one by searching the site or Google. Thanks!
|
# ? Aug 21, 2008 04:21 |
|
|
# ? May 8, 2024 07:04 |
|
1337JiveTurkey posted:Apache Derby claims to be fairly lightweight but I don't have much experience with it.
|
# ? Aug 21, 2008 09:40 |
|
F'Nog posted:It supplies a JDBC driver doesn't it support PreparedStatements? We use HSQLDB (H2 is another option, they both came about when Hypersonic forked) for the couple of instances we need an embedded database. Derby is an optional bundle with the JDK not the JRE so it's presence in an environment is something you'll have to make certain of anyway. Bundling a DB with the JDK is retarded anyway, it's too transient. I wonder if we'll get Glassfish when version 7 comes out. See, that's the kind of information I was looking for. I didn't know about PreparedStatements. I was just googling "java sanitize database" and the like and it didn't come up. Thanks!
|
# ? Aug 21, 2008 14:00 |
|
GT_Onizuka posted:Recommendations for a Java memory profiler? I don't want to attach it to any IDE as I need to run it all remotely. We're using Java 1.5. I have used JProfiler, and it is great, but it is not free. Since you are on java 5 why not try setting up an MBean interface and then remotely connecting to that via jconsole. That provides some remote monitoring functionality.
|
# ? Aug 22, 2008 03:40 |
|
hi, I want to readLine() from multiple BufferedReaders and do the same thing with the result (after some transforms, depending on the specific BufferedReader instance. Is there a better way of doing it than instantiating a thread for each reader? e.g. what I do now (this code is just written of the top of my head, but hopefully illustrates the point): code:
FWIW the BufferedReaders are based on InputStreams. I was thinking of trying to do something with the InputStream#available() method but I can't really think of anything obvious (un-obvious: re-implementing BufferedReader functionality in some sort of horrific BufferedReaderMultiplex?) adante fucked around with this message at 20:28 on Aug 22, 2008 |
# ? Aug 22, 2008 20:26 |
|
Working on a Java web project with servlets, and getting some really strange behavior. A bit of sample code works when run from a main() method, regardless of whether it's in a servlet class or a back-end class. When the same code is actually called in a servlet from the webpage, it fails. What this code does is connect to a secure webservice using client/server certificates for authentication, sends a query, and returns the result. In the case where this fails, I'm pretty sure it's because the client certificate isn't being sent properly (though the error message is vague, and it's possibly something else) - javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure Is there any reason why identical code could behave differently in these two contexts?
|
# ? Aug 22, 2008 22:05 |
|
adante posted:hi, I want to readLine() from multiple BufferedReaders and do the same thing with the result (after some transforms, depending on the specific BufferedReader instance. This article is old, but explains what I just said in more detail: http://www.ibm.com/developerworks/library/j-jtp0730.html
|
# ? Aug 23, 2008 01:19 |
|
Kilson posted:Working on a Java web project with servlets, and getting some really strange behavior. A bit of sample code works when run from a main() method, regardless of whether it's in a servlet class or a back-end class. When the same code is actually called in a servlet from the webpage, it fails.
|
# ? Aug 23, 2008 02:38 |
|
Incoherence posted:Depends how many readers you have relative to how long it takes for each one. If you have, say, a whole lot of readers, but for each one all you want to do is read a line, munge it a bit, and move on, the cost of starting that many threads may become a nontrivial portion of your runtime, at which point thread pools (java.util.concurrent.something) become an option. Right, I'm familiar with thread pools to an extent but my question was more: how do I do it when readLine() is a blocking operation and there is (as far as I can see) no non-blocking alternative? If you can provide some example code that, in a single thread, could check multiple BufferedReader#readLine() calls and service them/add them to a worker pool, I'd be interested in seeing it.
|
# ? Aug 23, 2008 06:32 |
|
adante posted:Right, I'm familiar with thread pools to an extent but my question was more: how do I do it when readLine() is a blocking operation and there is (as far as I can see) no non-blocking alternative? Basically, the only change I suggested is that instead of starting each "read, DoThing" task in its own thread, as your example does, you'd start each in a thread pool, which would have approximately the same result but wouldn't need to set up quite so many threads.
|
# ? Aug 23, 2008 07:55 |
|
Incoherence posted:The example you give calls readLine() within a thread, so thread pools don't really change that problem. I didn't get the impression from your post that that was your big problem, but maybe I wasn't reading it closely enough. If the readers are all reading from the same place (disk, network), they're probably going to be queued by something anyway. (I'm pretty sure hard disks can't read 500 different files at once. Could be wrong, of course.) You may as well have threads processing while they're waiting for I/O, and you may as well use a thread pool since you really don't need to start up and tear down N threads just to keep busy while you wait for N readLine calls. right, and what I meant is, I don't know how to do this. I don't see how it is possible to have N threads servicing M BufferedReaders where N < M. Maybe there is a misunderstanding here, but I think code speaks for itself. If you could provide some code/pseudocode that illustrates how to do this I'd be really interested.
|
# ? Aug 23, 2008 08:43 |
|
adante posted:right, and what I meant is, I don't know how to do this. I don't see how it is possible to have N threads servicing M BufferedReaders where N < M. Maybe there is a misunderstanding here, but I think code speaks for itself. If you could provide some code/pseudocode that illustrates how to do this I'd be really interested. In particular, what I think you want is this. This code sample is pretty close to what you're doing, I guess.
|
# ? Aug 23, 2008 09:11 |
|
code:
oh no computer fucked around with this message at 14:11 on Aug 23, 2008 |
# ? Aug 23, 2008 13:58 |
|
I don't know why at all but as soon as I added code:
|
# ? Aug 23, 2008 14:18 |
|
Ahh, it just seems to be a problem with writing stuff that big onto the console I think. I just created a text file and used a FileWriter to write the result to that and it works fine for much larger numbers.
|
# ? Aug 23, 2008 16:16 |
|
Incoherence posted:That's kind of the idea behind a thread pool. Instead of creating M threads that do one task apiece (as your example does), you create a thread pool with N threads, and you add your M tasks to the thread pool. The thread pool is usually implemented as a producer/consumer setup: the thread pool controller has a queue of work to do, and as worker threads finish what they were doing before they get work from the queue. lol we're just going around in circles. I keep saying I don't know how to create a clean solution that services M BufferedReader's using < M threads because readLine() can block and there's no way to tell if it will; and you keep saying "use thread pools!". Tell you what, if you can provide a solution (M BufferedReaders, <M threads) and implement it in this function, I'll paypal you $15. code:
|
# ? Aug 24, 2008 11:29 |
|
I think you are missing the point adante. If you use a queue, even though you have multiple threads, it's only going to allow one thread to DoStuff() at a time, so you don't have to worry about readLine() blocking. To reiterate what Incoherence said, thread pools and a queue definately sound like the way to go.
|
# ? Aug 24, 2008 17:11 |
|
adante, I'm fairly sure you'll need to create M readers, however you can service them with less than M threads. I whipped this up for my own understanding, it might help point you in the right direction.
|
# ? Aug 25, 2008 12:40 |
|
I'm using a MySql database with the jdbc connector. I get data truncation exceptions (or just truncated data if I set the jdbc compliant truncation to false) when ever I use a string of 32768 or more non-ascii characters as parameter in a PreparedSatement. The field it's writing for is a LONGTEXT field, which should be able to handle 4 billion bytes. I've tried PreparedStatement.setString and PreparedStatement.setCharacterStream, both give me the lovely data truncation error. The problem does not occur when I use an ascii-only string of more than 32k characters. Any ideas?
|
# ? Aug 25, 2008 15:24 |
|
triplekungfu posted:adante, I'm fairly sure you'll need to create M readers, however you can service them with less than M threads. if you mean I'll need to create M reader threads, then yes I agree. Otherwise.. well I still agree but you are reiterating the problem spec hey wiz posted:I think you are missing the point adante. If you use a queue, even though you have multiple threads, it's only going to allow one thread to DoStuff() at a time, so you don't have to worry about readLine() blocking. To reiterate what Incoherence said, thread pools and a queue definately sound like the way to go. Ok, MY point is that you guys keep suggesting I use a threadpool. Yes, a N-thread threadpool means my M threads will be very simple and the servicing goes into the N threads, but now I have M + N threads. This is not less than M threads. This is more than M threads! To re-iterate, my original question was if I could do it with less than M threads (well literally, 'Is there a better way of doing it than instantiating a thread for each reader?'). Either you are not answering my question, or you guys genuinely believe this can be done with less than M threads. If the former, that is not so helpful. If the latter then this argument is fast becoming academic. I will open up the $15 offer to anybody (paying out first correct solution only) so prove your point by implementing this and earn some easy cash. Rules apply (solution must be 'correct', use <M threads, no insane reflection tricks).
|
# ? Aug 25, 2008 21:25 |
|
adante posted:Ok, MY point is that you guys keep suggesting I use a threadpool. Yes, a N-thread threadpool means my M threads will be very simple and the servicing goes into the N threads, but now I have M + N threads. This is not less than M threads. This is more than M threads! To re-iterate, my original question was if I could do it with less than M threads (well literally, 'Is there a better way of doing it than instantiating a thread for each reader?'). Here's an example (borrowing heavily from triplekungfu, and probably not working): code:
|
# ? Aug 25, 2008 22:11 |
|
The non-blocking IO stuff in java.nio lets you deal with many inputs using very few Java threads. You stated before that you knew of no non-blocking alternative so there it is. It's not on Reader because Reader etc. predate all the non-blocking stuff they added in I think version 5. But really I'm kind of lost trying to figure out what all this bickering is about. For what it's worth an N thread pool to service M readers is still only N threads (Readers do not spin up their own threads - what would be the point?). It will only service N Readers at the same time, though, which kind of defeats the purpose. zootm fucked around with this message at 22:16 on Aug 25, 2008 |
# ? Aug 25, 2008 22:11 |
|
zootm posted:The non-blocking IO stuff in java.nio lets you deal with many inputs using very few Java threads. You stated before that you knew of no non-blocking alternative so there it is. It's not on Reader because Reader etc. predate all the non-blocking stuff they added in I think version 5. But really I'm kind of lost trying to figure out what all this bickering is about. here's the cliff's notes from my point of view: adante: I want to service M BufferedReaders using less than M threads [I do not explicitly state that I want it to work properly - as in all BufferedReaders being serviced regardless of input - but I kind of hoped it would be implied] Incoherence(after some back and forth): Use threadpools! hey wiz: Use threadpools! triplekungfu: [I think he is saying you need M threads but I'm not sure] + Here is some threadpool code! zootm: a threadpool with less than M threads will not service M BufferedReaders Anyway, at this stage one persons opinion will do for me. let's consider the discussion closed. For pedagogic reasons I will keep the $15 offer open (and even provide a quick and dirty test/example) if you can re-implement bindCallback to use, say, 3 threads -- so go for it team threadpool, easy money to be made. adante fucked around with this message at 01:04 on Aug 26, 2008 |
# ? Aug 26, 2008 01:02 |
|
Is it possible to utilize your graphics card in Java?
|
# ? Aug 26, 2008 06:23 |
|
rawstorm posted:Is it possible to utilize your graphics card in Java? Yes. There are OpenGL bindings for Java, that are cross-platform (that is its released for all major OS like windows, MacOS, Solaris and Linux). I am making web-start application in java right now, that utilizes JOGL (Java OpenGL). There are also more high level packages such as Java3D, and some other ones I forget. JOGL seems to be the most cross-platform one tho, and also fun to do if you already know some OpenGL. Here is link to their main page: https://jogl.dev.java.net/ If you decide to pick this up, feel free to ask me more questions through PM. I have a bunch of example code I did, and I will be glad to help.
|
# ? Aug 26, 2008 06:50 |
|
I made my own 3D engine and performance drops when I have too many textures. I know that the performance becomes low because there are too many points to rotate and translate so all I need is a way to make the graphics card do the rotations and translations to take some load off the CPU.
|
# ? Aug 26, 2008 08:07 |
|
adante posted:if you mean I'll need to create M reader threads, then yes I agree. Otherwise.. well I still agree but you are reiterating the problem spec No, that's not what I meant, in the example I gave earlier I had three threads servicing 15 objects. I got bored and whipped this up. There's 5 threads servicing brs.length BufferedReaders.
|
# ? Aug 26, 2008 12:27 |
|
triplekungfu posted:No, that's not what I meant, in the example I gave earlier I had three threads servicing 15 objects. zootm fucked around with this message at 14:09 on Aug 26, 2008 |
# ? Aug 26, 2008 13:57 |
|
rawstorm posted:I made my own 3D engine and performance drops when I have too many textures. I know that the performance becomes low because there are too many points to rotate and translate so all I need is a way to make the graphics card do the rotations and translations to take some load off the CPU. Is all your rendering done in software on CPU then? It is not easy to make the graphic cards do these calculations and then read them back. You would be better off making your renderer in OpenGL or Direc3D. The graphics card is good at doing mass matrix multiplies on all vectors that you send to it, but it was primarily designed as part of rendering pipeline. Perhaps you can use some GPGPU to do this, like CUDA, but I have no idea if that is possible on Java. I am not quite sure about this, but aren't there certain vector operations that CPU can do nowadays? You can make a C++/Assembly program to perform operations on matrices and vectors and use JNI to interface java with that program. You could also use CUDA this way I guess, but it would be pain in the rear end to do all that yourself.
|
# ? Aug 26, 2008 14:25 |
|
triplekungfu posted:No, that's not what I meant, in the example I gave earlier I had three threads servicing 15 objects. looks like 5 threads performing a SINGLE service of 15 BufferedReaders, once each. It also looks like if the first 5 BufferedReaders are not written to, but the remainder are, nothing will ever happen. Here is some code which demonstrates. Try and run that against my M thread test example to see how it should work. If you write any more code, try it against the test code to see if it works.
|
# ? Aug 26, 2008 14:28 |
|
adante posted:looks like 5 threads performing a SINGLE service of 15 BufferedReaders, once each. It also looks like if the first 5 BufferedReaders are not written to, but the remainder are, nothing will ever happen. I just took your original example and the code from the ExecutorService api and mashed them together. I didn't realise each reader needed to call service() more than once If it's possible/likely for the readers to block forever, I agree that this solution isn't going to work. But, to be fair, your original solution with N threads will never terminate either. Edit: I was pondering this further today, and I'm positive a thread pool won't work if the threads never terminate. the onion wizard fucked around with this message at 12:39 on Aug 27, 2008 |
# ? Aug 27, 2008 00:08 |
|
Quick question about servers and all that. I've made a quick little lightweight Java NIO server for Comet based connections, as I've quickly found out that the "workaround" Comet implementations is pretty unreliable for a high load event distribution. What I'll be doing is packaging the server inside a WAR file and have it deployable inside a real HTTP server like Tomcat/Glassfish/WebLogic/etc. I know those some of those servers already have an NIO if configured properly (Glassfish has grizzly, Tomcat has NIO HTTP protocol), but I want the WAR file to be able to be deployed on any Java server. I'm not that knowledgeable in server administration, but last time I tried to make a web service endpoint (using Java's lightweight HTTP server) inside of BEA WebLogic, it bitched a whole lot and I ended up not trying to deploy under WebLogic (worked in Glassfish just fine, though). I got around that by not being retarded and made it use the server it's being deployed on as the endpoint, but I need the lightweight NIO server running within the server I'm deploying to. I'm sure Glassfish would have no problem with this, but I'm also sure other servers are a lot more strict (like WebLogic!). Would this be a configuration issue? Should I get around this by running another VM?
|
# ? Aug 28, 2008 16:44 |
|
I have a question about find bugs, it reports a possible NullPointer on the bolded line.code:
|
# ? Aug 28, 2008 20:09 |
|
MEAT TREAT posted:I'm not sure if that's a real warning or just a false positive.
|
# ? Aug 28, 2008 20:13 |
|
The lesson is that everything that depends on input should be in the try block:code:
|
# ? Aug 28, 2008 21:04 |
|
That won't catch a NullPointerException though. You'll have to add a second catch block for that.
|
# ? Aug 28, 2008 21:07 |
|
Mill Town posted:That won't catch a NullPointerException though. You'll have to add a second catch block for that.
|
# ? Aug 28, 2008 21:16 |
|
Mustach posted:The lesson is that everything that depends on input should be in the try block: Duh. Thank you for clearing that up.
|
# ? Aug 29, 2008 00:46 |
|
Hi guys, I'm trying to pass a form data from a jsp into a java class which will perform some logic before forwarding to another jsp page. What is the best way to do this? I know how to pass a form data from a jsp to another jsp file using request.getParameter() but how do I do this to a Java Class?
|
# ? Aug 29, 2008 02:35 |
|
|
# ? May 8, 2024 07:04 |
|
BELL END posted:You don't catch unchecked exceptions, you fix your code. yeah in retrospect I suppose actually making sure the reference isn't NULL makes more sense.
|
# ? Aug 29, 2008 07:35 |