Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

BELL END posted:

I've never understood the big hullabaloo about this.
I think it stems from days when functions were bigger and inlining was a Bad Idea because memory was so expensive. So a return in one and only one spot ensured that any post-processing that had to be done - even on an error condition - would be done. I think it's similar to the faux pas of using goto except return only happens within a single scope. These rules were probably made before I was born though, so the guys that made the rules are too senile to even know that I'm breaking those rules now anyway.

Personally, I think a lot of "rules" like that are established in schools so that novice programmers learn to keep code easier to read and it's an unwritten rule that once you have a serious justification for it that all those old "rules" are irrelevant. That's kinda how I view rules in general, but unfortunately I keep getting flack for violating the "don't kill the mailman" rule because apparently I don't have enough experience killing people in general yet to justify killing the mailman.

Adbot
ADBOT LOVES YOU

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
Is there any way to create localizable annotations? The problem with annotations to me is that they're embedded in with the class and can't be localized easily. It's kind of a bitch having to use resource bundles at the moment to basically duplicate my comments in code externally, and I see myself repeating things a lot such that I'd rather just have a reference to a resourcebundle property within my annotations. I don't want to write property files any more, mommy :(

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
Most of the time when I write stuff, I treat a null string and empty string as the same thing. That is, it's the exception more than the norm that null and empty are distinguishable to me (but these days I'm not doing any SQL stuff, so I imagine that's the real reason to distinguish typically).

And really, an annotation for that? Wouldn't a straight-up method call to some static isNullOrEmpty method be faster anyway?

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

Idran posted:

Oh, you're right, I didn't even think about that. I always forget to check for null until it ends up biting me down the line, so that didn't even occur to me. Cool, I'll have to remember that convention, then.
And while you're at it, don't go do the if (null == possiblyNullObject) check religiously (instead of if (possiblyNullObject == null) ) like people do in C/C++ when you're doing Java - that convention has to do with C/C++'s lack of type constraints upon conditional expressions, which is enforced in Java (and C#) to be booleans. Some of my coworkers do that and it drives me nuts because then I go into C++ mode and I start having language shock and start wondering where all the free(ptr) and delete(ptr) calls went.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

Fehler posted:

Does anybody know where I could find sample code for comparing two WAV audio streams in Java? I need a function that returns some kind of "score" telling me how well the two streams match. From what I found on Google it looks like I need to do a Fourier Transformation, but I'm not really sure how to implement that and how to use it.
You're looking at not just FFTs but statistical methods to comparing data sets and signals like linear time series, clustering, Hidden Markov Models (HMMs), etc. Not exactly a walk in the park for beginners. I'm not aware of any Java libraries to do this though.

hexadecimal posted:

I am wondering how I can make my webservice return data without XML? That is I want the response to HTTPRequests to my webservice to just contain whatever the function returned, and no stupid XML wrapping that information.
So you're trying to turn it basically into a REST service because you're foregoing SOAP and XML-RPC. Axis2 theoretically supports REST-based messaging on HTTP transport (on the specs at least), but I haven't seen anyone manage to get it working.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

hexadecimal posted:

Is there a way to configure Axis2 such that bugs in my webservice don't gently caress up the whole axis2 service?
Wait, is it tying up the entire application server because Axis2 is hanging (an internal bug then), or can you run other axis2 based servlets in the application server?

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

hexadecimal posted:

I have some bugs in my webservice, that are probably threading related. However when it becomes unresponsive it blocks all other webservices. How can I make sure that my buggy webservice doesn't make other webservices and axis2 cry, besides the obvious "fix the bugs in the program"?
Your web service is causing resource starvation for other services, so there's little option but to fix it, or maybe use a JMX console to tell the JVM to kill the offending thread in your web service. The problem is, if your web service is jacked up enough, this method won't solve anything besides freeing up the thread schedulers a bit. Your time is best spent fixing it or at least limiting the resources the app receives. Well ok, it's technically possible to use "sandbox" an application to its own individual JVM depending upon support from the application server, but I haven't done it myself.

hexadecimal posted:

Stuff about RMI, SOAP, and HTTPRequests in Java
You're trying to wrap RMI within SOAP, which isn't pretty mainly because by using SOAP you remove possible system references due to transport + encoding (HTTP + XML / JSON) and are only left with logical ones. Serializing RMI requests into SOAP might as well be like trying to serialize RMI requests within other RMI requests - possible with some serious alchemy, but I think revising the architecture / design would be more productive.

On the other hand, what you're looking for has been done before, but the whole thing kinda makes me want to scream obscenities at all the useless compliance guys and standards-for-the-sake-of-standards attitude prevalent in so many organizations.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
So has anyone else messed around with dependency injection frameworks / libraries in Java? Google Guice seems to be fine for the jobs we've got, but we've got ourselves a home-brew dependency injection framework that is extremely clunky and I'm trying to get a better grasp on other options before overhauling the clunkiness we've got. I'm trying to keep it simple, but I do know I'm going to have to write a code generator to use any framework since what I'm working with is generated code that would take basically forever to perform the bindings manually. There aren't any dependency injectors that load class files and generate code for found classes according to some rules by chance, are there?

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

TRex EaterofCars posted:

Spring has a DI framework and I've found it decently powerful. With annotations it's not too bad to use, and configuration with Groovy is pretty easy.
I first thought about using Spring but umm... that's out of the picture for us given it's like taking a nuclear bomb strapped to a hammer when I just want a nailgun... unless I can completely strip out everything from Spring besides its DI framework. Groovy is currently out of the picture due to approval process issues that would keep me from doing any work for months or waste months of work if it was rejected.

TRex EaterofCars posted:

To answer your last question, do you have an example of what you're trying to do? If I understand you correctly, you want to do something similar to what Grails does. Grails (uses Spring) will load (and reload) arbitrary classes based on className by introspecting all classes in a given location. The "rules" are basically that the classes have to exist in a certain location. I'm sure you could do something similar.
Sounds useful, but related to what I said above, Grails is also likely a no-go. Also, it goes beyond class-loading - the class-loading is the trivial part for what I'm trying to do, in fact. I don't think I made myself terribly clear, so I'll try to show the gist of what we're trying to do.

==Scenario==

We have N classes with some similar looking method signatures:
pre:
package foo1;
public class A {
  public foo1.TypeA method1(..){..}
  public foo1.TypeB method2(..){..}
}

package foo2;
public class B {
  public foo2.TypeA method1(..){..}
  // method2 from A is not here
}
TypeA, for the sake of example, is actually identical across both packages. TypeB does not exist in the foo1 package.

We (try to) generate an interface with an offline code generator:
pre:
public interface IAB {
  public ITypeA method1(..){..} // invokes either A or B's method1 and returns an object that implements ITypeA, namely foo1.TypeA or foo2.TypeB
  public ITypeB fromA_method2(..){..} // 
}
... that is used by a generated factory class as follows (.
pre:
public class AB {
  public IAB newInstance(int version){
    switch (version){
      case VERSION_A:
        return newInstanceof_A_via_reflection();
      case VERSION_B:
        return newInstanceof_B_via_reflection();
      default:
        throw new FuckinNoobException();
    }
  }
}
What I want to do is use the factory in this manner:
pre:
public static void main(String[] args) {
    int version = Integer.parseInt(args[0]);
    IAB foo = AB.newInstance(version);
    foo.method1(..);
    if (version == WEIRD_VERSION)
      foo.fromA_method2(..);
  }
}
The basic idea is that the generated interface (perhaps abstract class?) IAB is the union of the methods of A and B with the disjoint set of methods still being accessible through that interface. Interface IAB could be the delegate for n many different classes with method1 possibly disappearing. A and B may be modifiable by hand, but there are a lot of classes and lots of methods per class. I'm actually concerned we will hit the maximum number of methods available for a class by the JVM and need to rethink this through (yes, that many classes, that many methods).

We're currently running a reflection service that resolves type references across multiple packages, resolves dependencies, creates interfaces to union them per roughly congruent class (we supply corresponding classes via canonical names), and generates factory classes and methods that have the sort of usage (poorly) shown above. I'm looking for something more elegant, documented, and flexible than what we have.


If you're curious about what beast might warrant all this, I'm trying to wrap an API that is evolving and I can never get rid of old versions nor their previous behaviors but somehow must provide access to all of them from a single API without incurring massive maintenance problems and to provide something concrete to quantify to other API developers how unstable their APIs are for their customers (political leverage on top of technical reasons - what's not to gain?). As new versions come up, we'd like to make adding support for the new API version's methods easier and to minimize memory footprint that would come with statically loading all the classes. So during runtime I pass the version number to be used to a factory that classloads the appropriate version of the library from disk and runs the underlying method or screams "not available in this version" if it's been idiotically removed. We'd like to have some compile-time verification of our unified API as well. Furthermore, I have maybe 10 or so of these API petting zoo collections to maintain... and growing.

zootm posted:

it'll enforce all (I think) of Java's type constraints so you don't get the exciting runtime problems due to erasure that you get with Spring XML
From what I've been reading about Scala, its type constraint system can be just as constrained as Java and more versatile. In fact, its lower type bound system is precisely what I want without going into full-on Ruby style duck typing + dynamic typing, which makes compile-time type checking less than useful. Java's typing system bugs the hell out of me, so I'd like to try something else, but as mentioned above, it's not exactly easy to do.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

TRex EaterofCars posted:

Is there any reason you can't just bundle revisions of the APIs in individual jars and dynamically classload them depending on the version? You could then introspect the classes made available by that classloader (I found a particulary neat way of doing this just now), and make your interfaces that way. Then you don't have to play traffic cop. Or perhaps I still don't get it :smith:
We basically do that already. Like I said, messing with clever classloaders doesn't help with resolving the methods from version to version that is the hard part - it resolves package name conflicts, but it gets complicated if you need to unload a class, for example.

My job is to review APIs, package them into a unified API convention system, test the bejesus out of them, and play traffic cop among the different API versions and for different API categories. Imagine you're trying to keep every copy of PHP since 2.0, remove / delegate away redundant functions, and make a single API that you call the "golden version" of PHP that's distributed to PHP developers. Given how lovely PHP's APIs are, this has some value to anyone that must use PHP but hates its APIs.

Oh, I took a look at Spring and it won't suffice for what we're trying to do - we'd have to generate XML instead of Java code like we do now basically. We're too far in the realm of "Java sucks for us, let's rewrite it" territory for it to work probably anyway.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
Struts and Tapestry are still wanted but are unlikely to be used in projects getting off the ground these days. Weblogic, JBoss, and Tomcat are still kings for "enterprise" application servers IMO. Never got a request for anything else besides Apache from my customers. For educational purposes, Stripes is certainly worth a shot - it looks quite fun, which is frankly a bit rare in the Java world to me.

Is there any professional value besides educational ones in messing with Glassfish? I don't know of any prominent organization that's used GlassFish to serve their applications, but maybe I'm missing someone huge that's used it. It may turn out like Django in the Python world though and take off after another year or so.

As far as jobs, it looks like few give a crap about your Java skills until you've spent 3+ years with Spring, Hibernate, Jboss, Tomcat, J2EE-specific frameworks, and a major DB or two. Otherwise, it's purely entry level it seems.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

csammis posted:

Which of course begs the question of why streams were engineered to throw exceptions on close in the first place, since you're right and there's basically nothing to be done at that point.
For the same reason that open files may not be allowed to close due to locking. You could either signal to another thread or remote process that the file resource should be closed on their end so you can close it, too. It's also possible for some pipes to be really flaky and require multiple closes with some delay in between. See: Windows readlocking horrors.

Sometimes I think monadic I/O is more sane than wrangling ridiculous try/catch/finally blocks that recursive expand into more try/catch/finally blocks.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

Sylink posted:

I think facebook uses java because it loads up the Java machine or w/e with the big coffee logo, unless javascript does that as well?

Would it be easier in Javascript?
Whether Java applets (the coffee logo and stomach-churning grind upon load) or Javascript is the right thing to use isn't much different from whether it's better to use Flash or Javascript - they are apples and oranges. Javascript is just the stuff that's written on the client, and if you're doing anything really advanced like encryption algorithms / hand-shaking protocols, I'd suggest not doing it in Javascript. If you're doing some basic text manipulation and maybe some very light image manipulation, Javascript could be the ticket to avoid temporarily turning clients' computers into nuclear reactors.

The most likely case of Java applets being used on Facebook is probably not from Facebook itself but some stupid ad. I can't really think of a good reason why image uploading would need Java on the client end unless you're adding some crazy stuff like photoshop-like features in your web browser.

Image upload functions are typically heavy on the server side, which Javascript doesn't apply to (unless you count stuff like HaXe). So you're probably looking at using a language like PHP, Python, Java, C#, and so forth on the backend to read off your images or zip / rar file that's uploaded. After you pick your language, pick your appropriate megathread and off you go.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
You're correct to look at jProfiler first to address basic performance problems of any sort. The only stuff beyond that would be things similar to Rational's Purify software, which is mostly of use to C/C++ developers and which could arguably be made mostly useless via use of Electric Fence. Code analyzers can be a bit misleading if you try to turn them into metrics generators or something. The best analyzers to me spit out run-time statistics of objects and suggest items that could be turned static for better refactoring (there was a custom in-house tool I had before to do this, there's probably a commercial one around).

One thing to watch out for when messing with the fun that is garbage collection is to actually understand what the metrics of garbage collection mean and to avoid tweaking. Holly Cummins from IBM had a pretty comprehensive overview of garbage collection at a talk I watched online a while ago, and at the very least you should remember some quick points that will help you avoid a lot of common pitfalls.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
Also, let's not forget that objects are objects and so require memory, and if you're running a heavily loaded system with this happening often enough, it can cause performance issues. But frankly, throwing exceptions is one of the last places to look for improving application performance, and if there is a problem, it's always been an I/O bottleneck that gets hit due to the exceptions (20k exceptions? Try 4TB of exception stacktrace data thrown / day to a single disk).

If you find little hope in the job you've got, it's in everyone's interest for you to move on. Don't think you're doing anyone a favor by staying. Just go. Even though the economy sucks, people are still hiring - several of my coworkers have left in the past 4 months and are obviously getting jobs, for instance.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
Due to the limitations of hardware (and software), at present there is no (consumer-available) system that can address the full 64 bit range of memory on our current 4KB page standard x86 addressing model. What we do have, however, are systems that can do 40, 48, and etc. bits of physical memory and so we can have enough memory addressable for the foreseeable future while hardware can catch up to the needs of such software. In some sense, we already had 40-bit memory systems a long time ago due to how addresses work in modern "32-bit" x86 systems, but the 8 bits weren't usable for anything that JVM designers would want to expand.

The reason you would care about a 64-bit JVM is if your Java application needs more than 3GB or so total of memory and you cannot distribute the data across multiple nodes in a distributed execution model. Also, due to fragmentation issues, you may require a 64-bit JVM even if you're not that close to 3GB of memory required.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

Tulenian posted:

Does the Sun 32-bit hotspot JVM actually support 3GB of memory? I've never been able to get it to allocate more than ~1.5GB. Any more and it just refuses to start.
Contiguous memory is the issue - I've seen cases where it won't start with more than 768MB for -Xmx. In a lot of configurations, you won't be able to allocate more than 1.5GB of memory in a single segment for the application. If you need more than 1 GB of memory for your Java app, you should be looking at 64-bit JVMs and OSes as part of a scaling strategy.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

zootm posted:

Of course you could consider scaling out instead of up with something like Terracotta, which to me looks like black magic.
We use that here for our clustering strategy (we were on jGroups+ Apache load balancing for a while *shudder*) and it's actually worked out quite well.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

Parantumaton posted:

Being interested in dynamic clustering, how does Terracotta scale in practice, do I have to bring the whole cluster down to add more nodes or can I dynamically pour more resources into it, what are the limits/caveats you've hit at with it etc?
I'm not on it, but from talking with the two other devs working on it, they haven't run into scaling problems except for I/O (typical for any clustering solution, haha) and there's nothing that would keep someone from adding more nodes on the fly, although I remember we uncovered some bugs with adding new nodes to a running cluster. The interfaces are pretty clunky and configuration looks disgusting though, which isn't surprising for such new software. The other guys have been working with the Terracotta devs to get all our stuff to work, and it does appear that we've managed to find bugs with their distributed JVM implementation that I am a little wary of recommending it for production right now. However, I do think it's worth a very serious look now for a lower-level clustering solution for your J2EE apps because everything should be fixed by the time staging is over for most environments.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

Parantumaton posted:

If your desired range is 1...7 billion and you can get to 2 billion, why not just do that one to three times, add those three together and then add another billion?
I'm almost certain that would introduce bias, which may or may not be acceptable depending upon how severe the bias is.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
The funny part is that the bytecode changed in other areas anyway, which means they might as well have let them change it.

I've always thought the worst thing about Java isn't the language but the JSR and JCP.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

fletcher posted:

Looking for a way to generate some charts in Java and output to an image. JFreeChart looks pretty sweet, anything else I should check out before diving in?
It doesn't actually fit your requirements, but if it has anything to do with showing a chart on a web page, you should probably look at Google Charts. The caveat is that it does require the user have some access to the Internet, so it breaks if they're in, say, a closed off datacenter.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
I should add a note that there is nothing in the Iterator specification that says that you must return the same item order for the same collection every time. It could be completely different each time even though nothing's happened to the data since the last time. It just so happens that people count from 0 to the end of the list for arrays and lists, for example, and we're all used to arrays returning the same thing every time as a silent, implied convention. This idea breaks down when you get into hash tables and data structures that have several intuitive ways to travel through all the elements.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

rawstorm posted:

Wow, this is really weird. I had Firefox open, and then I opened the program and it was running fine. Then I opened a new blank tab in Firefox and the program kept running fine. Then I went to https://www.cnn.com in the new tab, switched quickly back to my program, and it ran at normal speed for about 2 seconds and then suddenly started going really fast. What the hell is going on !?
Perhaps you're hitting something similar to what happened with people running Windows Media Player in the background to mess with core affinity and the Windows scheduler?

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
So I like python decorators. Is there a Java library that can provide some of the sugar to do something like it? I've realized that what I've written to strip a lot of boilerplate in my class hierarchies is better expressed in that manner. I'm not terribly familiar with Spring, but maybe I could use method injection in libraries like Guice or Tie to do something like a Python decorator in reuse of code through an annotation. DI is so awesome but it's hard to design with DI in mind sometimes and you'd rather wait until you actually need DI before your unit tests and mock objects get out of hand. So I'd try to make sure whatever solution I use doesn't conflict with Guice or Spring annotations. Last I remember both libraries do some bytecode weaving and the thought of breaking tools like that scares me.

Adbot
ADBOT LOVES YOU

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
I'd still prefer to get RAII / RAII-like conventions like C#'s using, although Closeables could be turned into syntactic sugar like for ( : ) loops, but given the history of the JSRB, I only expect :psyduck: after :psyduck: Always hoped to have something like a synchronized block become an arbitrary block reflecting the scope of an object's lifetime with the end of the block automatically invoking the finalize method. But... garbage collection and :effort:

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply