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
Luminous
May 19, 2004

Girls
Games
Gains
The JDK has VisualVM. It's been the recent go-to Java profiler for us recently.

Adbot
ADBOT LOVES YOU

Luminous
May 19, 2004

Girls
Games
Gains
Any Eclipse RCP experts in here?

At work, we're trying to migrate one of our applications to the Eclipse RCP framework. For the most part, it has gone well. But we're hitting some sticking points for what we want to do.

1) There is a large part of our system that, naturally, has nothing to do with the presentation side of things. However, we want to allow plugins to listen in on some of this stuff. Now, normally this would be easy: whatever class can just add a listener to our stuff. But, how is this accomplished in a plugin? How can a plugin get a reference to some system in the main application so that it can add a listener? Is the assumption that such a system would have a static access point?

2) Workbenches, perspectives, pages, views, editors, etc. Fun stuff, and seems to offer a lot of possibilities. We want to accomplish something specific with this that is, at the moment, looking like a brick wall of impossibility.

Let's say we have the main application, which consists of a view on the left side, and an empty area on the right (a placeholder). Now, in the placeholder area, we'd like new "windows" (not necessarily floating - they could be tabbed pages, as in when that area is an editor area). But, these windows need to have views inside of them, and this is where our lack of experience in Eclipse RCP shines. Have no clue on how to do that.

A window within our workbench that can have its own views - views that can only be arranged, docked, etc, within that particular window. Preferably through its own perspective.

So: main window has a view and a placeholder area. Place holder area can have multiple windows, each window having its own perspective of editors and views. Possible?

3) Is there any really good place of information? We have some older books, and the java doc pages, and snippets that they have. But, for the most part, it feels like information about Eclipse RCP is just all over the place, and not very well organized with good examples.

Luminous
May 19, 2004

Girls
Games
Gains
So, is that saying that if we want a plugin to listen to something external, then that external thing must also be a plugin (or, otherwise developed in the rcp way of things, whatever that may be)?

For instance, let's say we have SomePackage.SomeClass in its own project. This SomeClass could be used as is in other programs simply by instantiating a new one

code:
SomeClass somedummy = new SomeClass();
Now, of course a plugin could do the same thing, instantiate its own SomeClass. But, if our main class already has SomeClass, we just want the plugin to listen to events from it

code:
//Inside SomePlugin
<SomeClass ref>.addListener(new Listener() { ... });
where SomeClass ref is part of the main app, not defined in any of the plugin areas. Ideally with SomeClass ref being passed in through a constructor to the plugin, or through a setter.

I should have prefaced my last post with a "we are just beginning to learn Eclipse RCP and know nearly nothing" so, apologies for the near brain-deadedess of the questions.

edit: For my first question, it looks like Extension Points is what we were looking for. Will have to put something on that to test it out. Hopefully resulting in me not having to follow up question #1, ha.

Luminous fucked around with this message at 15:23 on Jun 10, 2010

Luminous
May 19, 2004

Girls
Games
Gains
Yeah, this seems to be working out well. Was just a step to realize that making something into a plugin doesn't mean it can no longer be used externally. Now that we're adding extensions and extension points, this is making a lot more sense.

I am still searching for a way to nest views and editors, as well as nesting a page in a page. The lack of information is leading me to believe this is impossible, which would be quite a shame as that changes our workflow concepts for the application :(

But if you, or anybody, know of a way (preferably simple) to get views into other views, then I am all ears.

edit: Or maybe I just want a new workbench window, which can have its own perspective. I just don't know.

Luminous fucked around with this message at 20:05 on Jun 10, 2010

Luminous
May 19, 2004

Girls
Games
Gains

TRex EaterofCars posted:

I'm not a "view guy", really. I know enough to be dangerous but I don't know the limitations of Eclipse's perspectives and views. I think you need to get the right terminology down and you'll probably find what you need.

Yeah, terminology is a bitch.

I do have another question regarding my first question, though: we have hit a little snag, and are hoping it is just our implementation (based off of the example provided here http://www.vogella.de/articles/EclipseExtensionPoint/article.html).

In that example, the plugin that handles the extensions loops through the extensions that implement the extension point. But, when it loops through, it is actually creating new instances. This means, for instance, trying to add a listener results in a listener being added, but for an instance of the extension that we aren't actually using. Hur.

The createExecutableExtension method seems to be the culprit for this, but we do not see a getExecutableExtension (for instance) that will get already existing ones. Maybe that's not even possible, as is.

So basically:
Plugin 1 defines an extension point and creates implementation code to loop through all implementing extensions and do something with them through the appropriate extension interface.

Plugin 2 defines some class that implements the appropriate extension interface.

Plugin 1 calls the appropriate extension interface, but on a "local" instance instead of the instance explicitly created in Plugin 2. What?

Luminous fucked around with this message at 21:31 on Jun 10, 2010

Luminous
May 19, 2004

Girls
Games
Gains
Ugh, Eclipse RCP is making me feel like a drooling retard. Why can I not find a simple example of how to share data across plugins?

I already have some classes that represent data and actions on that data, and want to create a plugin that can either (or both) display that data or trigger actions on that data.

I would have assumed this is a fairly common thing, but every example is so basic that you can't go anywhere from there. The only thing I can assume is that for such behavior, plugins expect static access points/factories. I've no real problem with this, but I simply want a yay or nay on if this is standard practice or if there is a different way that plugins accomplish data sharing and interaction.

Extension points are nice, but, they don't seem to provide what we're looking for and I am trying to figure out if I just need to shift my thinking and expectations even farther in order to get a grip on how Eclipse RCP wants things done.

This would be helped immensely by a simple application that has views in plugins that interact with or display data from some other plugin. The simplest example I've found that works is RSSOwl, and, that is far from simple.

Luminous
May 19, 2004

Girls
Games
Gains

magicalblender posted:

Is it possible to make a decorator class that doesn't call super() on its superclass?

Example code
I have a class Widget, which I can't modify the source code to. I want to know when methods frob() and troz() get called, so I make a decorator NoisyWidget, which alerts me when they get called. I instantiate a NoisyWidget and pass it to a function that takes Widgets.

I expect the output to be this:
code:
Doing lots of work...
function frob was called!
function troz was called!
but I get this:
code:
Doing lots of work...
Doing lots of work...
function frob was called!
function troz was called!
It looks like Java is inserting an implicit super call in the NoisyWidget constructor. This is causing it to do 100% more work than it needs to. Is there any way to tell Java, "no thanks, I really don't want to call super(), implicitly or otherwise"?

I suspect this post might be an XY problem, so I'll also ask a higher-level question. I want to monitor Widget's methods - how else can I do this?

While you've received other responses, I am going to throw out these two questions: 1) do you need to use a decorator pattern here? 2) does the base Widget class need to be doing all of that work?

Luminous
May 19, 2004

Girls
Games
Gains

MariusMcG posted:

Hopefully the good folks in this thread have helped you to find a short-term solution; but if you're still interested in this topic, there's a book called Java Concurrency in Practice that is (in my opinion) worth a read for anyone who's writing Java.

Man, I saw the question, and starting reading the replies, just waiting, hoping, nobody would post this so that I could do so. This is a really great book for understanding threading issues in general, and getting a grip on what Java can provide to you.

Luminous
May 19, 2004

Girls
Games
Gains

Malfeasible posted:

in my mind in both scenarios Java is creating a String from data containing the '\n' character sequence

You should verify that.

Luminous
May 19, 2004

Girls
Games
Gains
Well, I don't know specifically an answer (never used), however, the documentation MimePart.getContent says that it always returns a subclass of MultiPart for objects that are a multipart type, which I assume your MimeBodyPart would be in this case.

Luminous
May 19, 2004

Girls
Games
Gains

Kamakaze9 posted:

Not quite what I wanted to do with it, but it will work and I'll use it unless I figure out how to accomplish my goal or at least how to better articulate it. Thanks for all the help.

Also, is there a more specialized irc channel you use or does everyone pretty much hang out in cobol.

People are getting caught up on the array issue, and the fact that, in this case, the array index corresponds to an id.

If, for instance, the Accounts were a Collection<Account> then 1) the idea that the array index happens to also be the account id disappears, and 2) people would probably be giving you ideas for searching that collection.

For instance, the most basic search, a simple linear search, would be to just loop through every Account in your collection, checking if the id you're looking for is the same as the id of the account currently being evaluated. If it is, return that account. If not, continue on until all of the accounts have been evaluated - in which case, you go to your error case of asking the user to enter a valid account id.

Luminous
May 19, 2004

Girls
Games
Gains

Red_Fred posted:

Your guess was spot on that the elevator can only hold 4 people so the array is for 4 variables. However some of them will be null because it's up to the input as to what people are on what floor and if they need picking up etc. Should my loop be <= instead of < ?

Do I need to add in something to ignore null values?

As for two loops, I don't know. Some guy suggested it today when he was giving me some help, it seemed a bit strange later on.

Thanks!

If null values are acceptable input (i.e., a single person in your person array) in your program, then yes, you need to make sure your program can appropriately handle that case.

Luminous
May 19, 2004

Girls
Games
Gains

Aleksei Vasiliev posted:

no it doesn't

you initialize one DataStructure, then have three threads each get a reference to its array member

Unless some of the code you left out says "array = new int[blah];" in the getArray() method, they are all referencing the same array

Ding ding.

The simplest way to prove this to yourself is to move all of your print statements inside of the .getArray function, at which point you ought to see the behavior you are expecting.

But encapsulation is pretty important if you want to ensure well functioning poo poo. Return a copy of the array.

Luminous
May 19, 2004

Girls
Games
Gains
Has anybody encountered problems with JAXB between Windows and Linux?

We have been using JAXB to read in a 3rd part XML file into java object representations (autogenerated from the schema by xjc).

On Windows this seems to work perfectly. All data is present and accounted for in their appropriate objects.

On Linux data is missing, but no errors are emitted using a ValidationEventHandler, and the JAXB content indicated it knows about the classes (using .toString).

At a loss as to what the problem is.

Luminous
May 19, 2004

Girls
Games
Gains

Paolomania posted:

Any chance you are using an open-source non-Oracle JVM? Some Linux distros such as Debian use these by default and I have noticed some subtle differences.

Good question, actually. I'll forward along the question to whoever setup the OS.

But, on the other hand . . . things magically started working. I hate these types of problems.

My first thought was that whoever did the build didn't update, but I did watch them update and deploy. And I watched the incorrect results.

So, still at a loss and its equally concerning that it has started working properly.

Luminous
May 19, 2004

Girls
Games
Gains

Aleksei Vasiliev posted:

code:
	private final ExecutorService pool = Executors.newFixedThreadPool(5);

		/* ... */

		CompletionService<Boolean> comp = new ExecutorCompletionService<Boolean>(pool);
		List<Callable<Boolean>> tasks = new ArrayList<Callable<Boolean>>();
		for (int i = 0; i < files.length; i++) {
			File infile = files[i];
			File outfile = new File(outdir, infile.getName());
			tasks.add(new CrushTask(crusher, infile, outfile));
		}
		for (Callable<Boolean> t : tasks)
			comp.submit(t);
		for (int i = 0; i < files.length; i++) {
			try {
				boolean res = comp.take().get();
				System.out.println(res);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
This code only half works. It's optimizing PNG files by spawning up to 5 instances of pngout.exe, running on a directory of PNG files. Every one of them does get optimized, that isn't the problem.
The problem is that some images take a loong time to compress, 30+ seconds. Most take <5. Whenever it runs into an image that takes a long time, it stops spawning new pngout instances, so I end up with one thread running and four doing nothing at all. Isn't the entire point of an ExecutorService that the other threads can keep working? What am I doing wrong here?

It still cuts 40% or so off the single-threaded time, but it could be doing a lot better.

Can doesn't mean they will. A simple example would be a task that uses a resource that can only be utilized by one thread at a time - using an executor of multiple threads with such a task wouldn't accomplish much. That doesn't seem to be the case here at first glance, although who knows what is going on in CrushTask.

How are you verifying that all other threads are idle when one thread hits a "long image"?

Luminous
May 19, 2004

Girls
Games
Gains
You should use waitFor if you want to block until the process ends, which is what your second method there is essentially doing, just in a roundabout way.

If you need to consume the standard output (you probably should, as it can lead to blocks if you don't, unless you know pngout has no output) then 1) you should be consuming standard error as well and 2) you need to do this in a concurrent manner (read the stdout and stderr both from separate threads).

Kicking off the stream reads should happen before the waitFor call.

Here's some brief but extended reading:
http://stackoverflow.com/questions/1088941/java-reading-standard-output-from-an-external-program-using-inputstream
http://stackoverflow.com/questions/611760/java-inputstream-read-blocking

Luminous fucked around with this message at 14:40 on Jul 4, 2011

Luminous
May 19, 2004

Girls
Games
Gains

Aleksei Vasiliev posted:

I can't use waitFor without consuming the entire stdout. If I call waitFor before that, then it will block forever. The pngout process will eventually go to 0% CPU usage and just sit there doing nothing until I terminate my program. But if I consume the stdout , then the thread will lock, hurting performance a lot.

I am consuming stderr, it's redirected to stdout.

The only output I need from pngout is the exit value, I'm running it in quiet mode anyway.

e: tested and edited to represent reality

I know you had addressed waitFor before, but I think you need to re-look there. In particular, the first link I give has another link to an old article that shows one solution of how to empty stdout and stderror concurrently and in conjunction with waitFor.

Luminous
May 19, 2004

Girls
Games
Gains

Hidden Under a Hat posted:

Can you go into a little more detail about this and how to use it? I think the issue with my program locking up may be due to out of memory but I'm not sure. I'm using JFreeChart and have several graphs worth of data plotted every 1-5 minutes for several days.

You can use the heapdump with something like http://www.eclipse.org/mat/ to see what your application has been up to and then beat it over its head until it behaves like you want.

Luminous
May 19, 2004

Girls
Games
Gains

HFX posted:

Using it for the method you describe cries that you should implement an interface that Instrument classes subclass to provide that method. It is considered bad form when you are using it to basically serve as the old dreaded C 200 line if..else if.. statement. Basically, used too liberally it can point to issues with design.

Now that I've said that, it is important to remember that instanceof is the only way to handle certain situations (especially when dealing with code older then Java 5). People who automatically dismiss it as bad, are the same people who think dynamic_cast in C++ is terrible.

You're right that its not always inappropriate, but I'd much rather people default to thinking it bad than not. The cases where it is used inappropriately (i.e., they created a poor design and aren't willing to fix it) seem to be far more widespread than appropriate uses.

Luminous fucked around with this message at 17:56 on Aug 31, 2011

Luminous
May 19, 2004

Girls
Games
Gains

MonsterUnderYourBed posted:

simple question with the JDBC hooking into MySQL.

Is there a way I can insert an entry, and at the same time return the automatically generated key that entry is now using?

I am aware that I can insert an entry, stating the automatic key should be returnable, and then get the key for the final entry in the database, but if multiple processes are accessing the database, this could return an incorrect result due to a second entry being added in before the key is returned.

Also a note, but I believe getting the last inserted keys is safe from other concurrent access so long as it is in the same transaction.

Luminous
May 19, 2004

Girls
Games
Gains

Sylink posted:

Sorry my typing is awful. I meant I wanted to compile things from a command line after writing whatever in a text editor. Not using EZ mode IDE.

I think a better approach would be to tell us what you expect to gain by using just a command line, and then we could tell you whether or not what you expect is an accurate extrapolation of what will happen.

Luminous
May 19, 2004

Girls
Games
Gains
You may want to consider an account as, well, just an account that has f.ex, a username and a role or a list of roles, where a role is an admin, a mod, or a schmoe (use inheritance here).

Then serializing an account and determining which actual role objects need to be instantiated is more straightforward.

Luminous
May 19, 2004

Girls
Games
Gains
Nothing is wrong with Eclipse. Some people just don't like certain IDEs.

Luminous
May 19, 2004

Girls
Games
Gains

Nighttheii posted:

This is probably too basic of a question, but I have an object class and method where RationalNumber is an object with the two int variables numerator and denominator.

This method "add" is supposed to use the RationalNumber object as the return type, allow the main program to add a 2nd RationalNumber to the first (not worrying about lowest common denominators) changing it's value.

What do I put in the return statement for the add method? (There might be other problems, i'm kind of new at this.)
code:
public class RationalNumber {
    int numerator;
    int denominator;

    public RationalNumber(int newNumerator, int newDenominator) {
        numerator = newNumerator;
        denominator = newDenominator;
    }
    public RationalNumber add(RationalNumber other) {
        if (denominator == other.denominator) {
            numerator += other.numerator;
        } else {
            int temp = 0;
            denominator = denominator * other.denominator;
            temp = denominator / other.denominator;    
            numerator = (numerator * temp) + (other.numerator *temp);
        }
        return _____;
    }
}

return new RationalNumber(numerator, denominator);

However, understand that your logic modifies the value of the rational number you're using already.

code:
RationalNumber first = new RationalNumber(1, 2);
RationalNumber second = new RationalNumber(3, 4);
RationalNumber third = first.add(second);
In this case, both first and third are representative of the same RationalNumber you want.

I'd personally recommend eliminating that side effect so that first remains unchanged. This is accomplished by introducing local variables to the .add method, not modifying the class members for numerator and denominator, and then using those (the local variables) as the input for a new RationalNumber.

Luminous
May 19, 2004

Girls
Games
Gains

Lord Of Texas posted:

Have you never had to test code that depends on an external service? Mocks are extremely useful for when you are trying to actually create unit tests, and integration tests. I suppose they could be overdone, but at my shop they're underutilized.

I think this is a big point, and if I recall, has been debated in this thread before. But the lack of understanding about the different types of testing that code can and should undergo can lead to excessive or improper use of helpful technology. Even in testing, it's still about using the right tool for the job - but you need to know what the job is first.

Luminous
May 19, 2004

Girls
Games
Gains

Win8 Hetro Experie posted:

Making things actually immutable is a lot more work than deciding not to mutate things that should be immutable.

Making things immutable is easy and less work than deciding "I don't want this to mutate, so I won't mutate it" and hoping everybody else that uses your code one day knows what you were thinking or remembers all of your documentation on the issue.

I don't really get why people find making things immutable difficult. It's literally CS101.

Adbot
ADBOT LOVES YOU

Luminous
May 19, 2004

Girls
Games
Gains

Fluue posted:

That actually sounds like it would work for what I'm trying to accomplish. Coming from a PHP background, I'm still adjusting to strong typing and built-in classes.

And not to seem like I'm abusing this thread, but if anyone has a minute, could you look over this Java gist and see if they can tell where I'm going wrong building a custom LL implementation? I'm getting null pointer exceptions and my data isn't loading into the linked list...

https://gist.github.com/verkaufer/486633bc47fd1c735f44

What do you think this.head = head and head = this.head actually do?

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