|
horse_ebookmarklet posted:I'm confused about CancelledKeyExceptions and a SelectionKey when using NIO Selectors. An unchecked exception is the library's designer indicating that they don't expect you to want to, or know how to, recover from this error. (IMO, IOException really ought to be a RuntimeException.) You don't need to feel bad about catching RuntimeExceptions if you know what they indicate, and how to recover. You should be extremely careful catching Throwables, because there are very, very few situations where you can reasonably recover from an Error, but any exception thrown is just the library designer communicating information upwards. I'm not familiar with your specific application, but, er, why do many threads need access to the same channel, with any of them capable of closing it? If at all possible, I would personally prefer to refactor the code so that there's only one reference to the channel inside of a wrapper class that maybe exposes something a little more high-level than pushing and pulling bytes. I'd add synchronization logic within that class to ensure that my channel is readable before I read from it - since the reads are all happening within one class, it's much easier to ensure that everyone is following the same synchronization rules. If what you're trying to implement here is basically a Queue, with a bunch of worker threads taking the same type of information out of the channel as quickly as it's available, I'd look into using Guava's thread-safe Queues here; you'd have one thread that pulls information out of the channel as it becomes available and puts it into the queue, and then N worker-threads each pulling information out of the queue. You're doing all of the unsafe work within one thread, and then leveraging Google's experience at writing thread-safe code to make sure that your worker threads never step on each other's toes.
|
# ? Sep 21, 2014 22:59 |
|
|
# ? Jun 1, 2024 12:55 |
|
Nothing returned by Queues isn't in the standard java library.
|
# ? Sep 22, 2014 00:56 |
|
horse_ebookmarklet posted:I'm confused about CancelledKeyExceptions and a SelectionKey when using NIO Selectors. Queues are a good answer here; put the socket close on the selection thread by adding an operation queue.
|
# ? Sep 22, 2014 00:59 |
|
As a stop gap I am catching and recovering from the RuntimeException. It seeeeems to work. The application architecture currently has a thread where the selector parses tasks (Over TCP) and submits the tasks to a queue, and a number of workers in a pool poll for these tasks. Similar to the architecture suggested. The tasks are computations that are sent back to the client that requested it. When the task is complete the worker attempts to write the result back to the TCP socket. A client can submit multiple tasks to be computed simultaneously, so multiple workers can write back. I have a wrapper around the SocketChannel that handles synchronization and currently closes the socket channel if something unexpected happens (write() failure or application specific event in the worker). It sounds like it would be better design to signal the selector thread to close the socket. Next time the selector returns, 'reap' any socket channels that have a 'close pending'.
|
# ? Sep 22, 2014 01:54 |
|
horse_ebookmarklet posted:It sounds like it would be better design to signal the selector thread to close the socket. Next time the selector returns, 'reap' any socket channels that have a 'close pending'. Yup. Do all the I/O touching on the selector thread and then you're not fighting the design.
|
# ? Sep 22, 2014 03:09 |
|
Java EE/ EJB question: Currently I have a very simple MDB example with a servlet using JMS to talk to a bean. The ConnectionFactory and Queue are specified using @Resource injection in both the servlet and the bean. For the bean: code:
code:
|
# ? Sep 23, 2014 19:04 |
|
I'm trying to use the new LocalDate class in Java 8 and for some reason I'm getting an error in IntelliJ that its constructor is private, despite the javadoc listing it as public. I expect I'm missing something fairly obvious here. I've imported the correct package. I just want a toString() friendly date format without any time information.
|
# ? Sep 26, 2014 14:09 |
|
Chas McGill posted:I'm trying to use the new LocalDate class in Java 8 and for some reason I'm getting an error in IntelliJ that its constructor is private, despite the javadoc listing it as public. You linked the javadoc for Joda time. The LocalDate class in Java 8 has no public constructors and instead supplies statics methods to create a new local date. http://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html HFX fucked around with this message at 15:13 on Sep 26, 2014 |
# ? Sep 26, 2014 15:11 |
|
HFX posted:You linked the javadoc for Joda time. The LocalDate class in Java 8 has no public constructors and instead supplies statics methods to create a new local date. I got the result I wanted with this: LocalDate dob = LocalDate.of(1950,10,14); Chas McGill fucked around with this message at 15:17 on Sep 26, 2014 |
# ? Sep 26, 2014 15:14 |
|
Chas McGill posted:That's what I get for googling something and looking at the first result without thinking about it! I think I was still thinking in terms of the old Date class, which does have a public constructor. It's okay. At least you get to play with cool features. Work just crushes me by forcing me to stay in the bounds of Java 6 if I'm lucky.
|
# ? Sep 26, 2014 15:55 |
|
HFX posted:It's okay. At least you get to play with cool features. Work just crushes me by forcing me to stay in the bounds of Java 6 if I'm lucky. Well, I just finished a couple of Java modules so this is just for a personal project to stop everything I learnt from leaking out of my brain now that they're over. I remember worrying that what I was being taught would be obsolete within a year, but that was before I understood how much legacy work there is.
|
# ? Sep 26, 2014 16:01 |
|
Chas McGill posted:Well, I just finished a couple of Java modules so this is just for a personal project to stop everything I learnt from leaking out of my brain now that they're over. I remember worrying that what I was being taught would be obsolete within a year, but that was before I understood how much legacy work there is. Average large corporation development: New version (Java 8): Can't use it. It isn't test it. What if all our crappy applications don't work. Old version still supported for security (Java 7): Can't use it. What if our applications break. We will move there in 2-5 years. Old version EOL'd (Java 6): This is our current standard. All projects including new projects should target this. Don't worry. Average industry is almost always 10-15 years behind academia when it comes to software.
|
# ? Sep 26, 2014 16:25 |
|
Oracle are happy to support any version of Java for a large bag of coin. There is a page somewhere, I recall it going back at least to version 1.3, this page has version 5 supported for eternity: http://www.oracle.com/technetwork/java/javase/eol-135779.html MrMoo fucked around with this message at 01:12 on Sep 27, 2014 |
# ? Sep 27, 2014 01:09 |
|
Created a java application which uses axis to call some web services. One of my calls is returning this object and I am unsure how to parse it. code:
System.out.println result code:
|
# ? Sep 29, 2014 15:28 |
|
This looks like the toString method of that object is producing this XML. Since you're getting this from a webservice, and since it would be incredibly dumb to send an XML string over SOAP, most likely that element is a proper object (that may need casting) to be accessed nicely (call public methods, set/get/etc.). Debug through it to see what kind of element is it (or just print getClass()). If you really are getting an XML string over soap (I'd brush up the resume and get out of there asap), i guess all you have to do is parse said xml (jaxb is an easy way to do it and is integrated in the jdk, but there are bazillions of libraries to parse an xml out there).
|
# ? Sep 29, 2014 15:37 |
|
The web service is from a client I am interfacing with.. And yes they are returning XML.
DholmbladRU fucked around with this message at 18:12 on Sep 29, 2014 |
# ? Sep 29, 2014 15:41 |
|
DholmbladRU posted:The web service is from a client I am interfacing with.. And yes they are returning XML. Then no wonder people are complaining that "SOAP is haaaaaard" since all they're using it for is to send strings (as XML) over the net, instead of objects. Well then, if you cannot beat them over the head with the knowledge bat, i guess you're stuck having to parse XML. You can make it somewhat easier for you if you create the object model properly and then tell jaxb to parse the XML and store it in the object model (which is what the SOAP library would have done for free). The code would be something like: code:
|
# ? Sep 29, 2014 18:25 |
|
Volguus posted:
Thanks! I ended up writing below which gets me to the elements I needed. But it looks slow.. code:
|
# ? Sep 29, 2014 18:32 |
|
DholmbladRU posted:Thanks! I ended up writing below which gets me to the elements I needed. But it looks slow.. Hey, hold on a second. OMElement is part of the axiom package. Did you generate the webservice classes from the WSDL? Or are you answering client's call from a plain servlet?
|
# ? Sep 29, 2014 18:56 |
|
Volguus posted:Hey, hold on a second. OMElement is part of the axiom package. Did you generate the webservice classes from the WSDL? Or are you answering client's call from a plain servlet? I generated the webservice classes from the wsdl and am leveraging them to make the WS call. DholmbladRU fucked around with this message at 19:05 on Sep 29, 2014 |
# ? Sep 29, 2014 19:03 |
|
Seems to me you're doing something wrong. You shouldn't even be touching the DOM tree and manually parsing XML in order to use a webservice.
|
# ? Sep 29, 2014 19:59 |
|
DholmbladRU posted:I generated the webservice classes from the wsdl and am leveraging them to make the WS call. Ok, then why are you playing with the apache package? Should have something like (since you're the server apparently): code:
|
# ? Sep 29, 2014 21:24 |
With Tomact 7, what's the difference between just dropping a war file into the webapps directory vs. using tomcat manager to deploy the war file?
|
|
# ? Sep 29, 2014 21:56 |
|
So I recently started my CS degree with the Open University. Its meant to be part time but I have elected to study 3 modules at once, so its full time! My first modules are going well but I have been looking ahead and the course teaches 2 Java modules next semester. This wouldn't normally be an issue but I am studying them at the same time, so beginner and intermediate at the same time! I have some experience of Python but have never touched Java. What should I be looking at for online tutorials and stuff to give myself a fighting chance next semester.
|
# ? Sep 30, 2014 19:30 |
|
thegasman2000 posted:So I recently started my CS degree with the Open University. Its meant to be part time but I have elected to study 3 modules at once, so its full time! My first modules are going well but I have been looking ahead and the course teaches 2 Java modules next semester. This wouldn't normally be an issue but I am studying them at the same time, so beginner and intermediate at the same time! I have some experience of Python but have never touched Java. What should I be looking at for online tutorials and stuff to give myself a fighting chance next semester. Are they teaching Java or concepts in Java? Can you give us a bit more information (course syllabus, module description, etc).
|
# ? Sep 30, 2014 19:48 |
|
HFX posted:Are they teaching Java or concepts in Java? Can you give us a bit more information (course syllabus, module description, etc). The modules are: Object-oriented Java programming (M250) This module concentrates on aspects of Java that best demonstrate object-oriented principles and good practice, you'll gain a solid basis for further study of the Java language and object-oriented software development. Software development with Java (M256) Discover the fundamentals of an object-oriented approach to software development, using up-to-date analytical techniques and processes essential for specification, design and implementation.
|
# ? Sep 30, 2014 20:36 |
|
thegasman2000 posted:The modules are: I will recommend these two places to start: http://docs.oracle.com/javase/tutorial/java/TOC.html https://thenewcircle.com/static/bookshelf/java_fundamentals_tutorial/index.html The first class will probably be the basics of object oriented programming. The second one seems like it would be an extension of the first including teaching when to abstract, design patterns, etc. Both descriptions are sufficiently vague to tell you exactly what you can expect.
|
# ? Sep 30, 2014 23:47 |
|
thegasman2000 posted:The modules are: Mate, I just did those two modules. Don't worry too much about it. If you have any programming experience you'll be in a better position than I was to start with. M250 is baby's first java and M256 is jargon memorisation. Feel free to ask me any questions about the modules. I got a distinction for M250 and I'm anxiously waiting on the M256 results. for (Frog eachFrog : frogTribe) { eachFrog.croak(); } if (kermit.isGreen()) { kermit.matingDance(); } edit: Feels weird to see someone posting about the OU on here. Chas McGill fucked around with this message at 23:55 on Sep 30, 2014 |
# ? Sep 30, 2014 23:50 |
|
fletcher posted:With Tomact 7, what's the difference between just dropping a war file into the webapps directory vs. using tomcat manager to deploy the war file? I don't think there are any differences. But you can probably more easily automate an app deployment using the manager application, rather than just scp it in there (from the build system for example).
|
# ? Sep 30, 2014 23:58 |
|
Hello Java friends - any chance there's an established pattern or something for this kind of thing? I'm trying to make a superclass with some generic functionality, that can handle the specific details added by the subclasses. I want each subclass to be able to add some fields of various types, and pop them in a map pointing to their associated keys. Then the superclass will iterate over the map, grab each field variable, and call a method appropriate to its type. So something like: Java code:
|
# ? Oct 1, 2014 00:06 |
|
For a Java classroom assignment, I created a superclass Employee, and Manager and Engineer classes inheriting from Employee. I am trying to create an array of type Employee, and initialize some Managers and Engineers inside of it at the same time as declaring the array, but I can't figure out the syntax. I know about int [] a = {1,2,3,4,5} but can't find an equivalent like Employee [] a = {Engineer bob("bob","dobson"), Manager eric("eric", "ford")…} How to do?
|
# ? Oct 1, 2014 03:25 |
|
Progression Please posted:For a Java classroom assignment, I created a superclass Employee, and Manager and Engineer classes inheriting from Employee. Employee[] a = new Employee[] {new Engineer("bob","dobson"), new Manager("eric", "ford")…} iirc, on mobile.
|
# ? Oct 1, 2014 03:35 |
|
Yeah you need to create each object in the array, which is what the new keyword does. It basically calls a constructor, so new Engineer("bob","dobson") is really calling the Engineer class's constructor with those two parameters, which does its business and creates the object, then new returns the reference. So your array creation code sort of ends up like Employee[] a = { ref1, ref2 }; Like how int[] a = { 1+1, 2*5 }; will evaluate the stuff inside first and end up with int[] a = { 2, 10 };
|
# ? Oct 1, 2014 04:00 |
|
thegasman2000 posted:The modules are: I started those at one time about 10 years ago, they started easy and then got mega hard even for a seasoned pro, I hope you have lots of time as there was soooo much studying. Although they keep saying that courses are being dumbed down. TheresaJayne fucked around with this message at 07:22 on Oct 1, 2014 |
# ? Oct 1, 2014 07:20 |
Trying to setup SSL on Tomcat (APR):code:
code:
|
|
# ? Oct 1, 2014 07:27 |
|
TheresaJayne posted:I started those at one time about 10 years ago, they started easy and then got mega hard even for a seasoned pro, Both exams were balls hard though.
|
# ? Oct 1, 2014 08:48 |
|
Looks like I am going to have fun then! I take it the exam is the vast majority of the grade too :/
|
# ? Oct 1, 2014 09:42 |
|
thegasman2000 posted:Looks like I am going to have fun then! I take it the exam is the vast majority of the grade too :/ The most advanced thing you'll do in M250 is probably reading from and writing to CSV files, or iterating through collections. M256 has very little programming since it's mostly theoretical. The course materials for both modules is extremely wordy, so if you're struggling with any concept you can probably just google it and find a much more concise explanation on stack overflow/youtube/javadocs. I will say that I feel like M250 gave me a decent grounding in Java basics and M256 got me interested in design patterns etc.
|
# ? Oct 1, 2014 10:01 |
|
fletcher posted:Trying to setup SSL on Tomcat (APR): Whats the folder permission (.) if its owner is root, group root and permission 770 then nothing can see into the folder, of course for folders you have read write and execute, but they mean different things. you may need to add execute to allow access to the folder.
|
# ? Oct 1, 2014 13:17 |
|
|
# ? Jun 1, 2024 12:55 |
|
fletcher posted:Trying to setup SSL on Tomcat (APR): Try changing your permission to 644. TheresaJayne posted:Whats the folder permission (.) if its owner is root, group root and permission 770 then nothing can see into the folder, I agree this may also be an issue, but I though you could read from a file with that permission owned by someone else but perhaps not root? Since I am at work, I don't have a linux box where I have root access with which to test. HFX fucked around with this message at 14:10 on Oct 1, 2014 |
# ? Oct 1, 2014 14:07 |