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
Colonel Taint
Mar 14, 2004


I'll try changing it to a fixed thread pool. Ultimately I would like it to be unbounded, and I'm really hoping that changing it will be somewhat revealing.

Edit:
Ah-ha! Actually I think I know what the problem is. You're right about the callback thing. This is a group (school) project where not all members of the group are really at the same level. I forgot... earlier on in the project I decided to model the thing using callbacks, and they`re all in place. However, these callbacks are not currently executed asynchronously from anyone else's side of things. Guess what I'll be doing today.

Colonel Taint fucked around with this message at 18:00 on May 9, 2010

Adbot
ADBOT LOVES YOU

HondaCivet
Oct 16, 2005

And then it falls
And then I fall
And then I know


Psychorider posted:

You should post the rest of the function so we can see why it doesn't work. The only thing I can think of is that you may close too many brackets and you end up outside the loop.

I checked that. If I just change it to a plain for loop that works its way through the ArrayList it works fine. Bah.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

HondaCivet posted:

I checked that. If I just change it to a plain for loop that works its way through the ArrayList it works fine. Bah.

Is that definitely the only thing you changed?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Jonnty posted:

Is that definitely the only thing you changed?

Yeah, you should probably show us the entire loop so that we can help. Your original sample wasn't enough to figure out the issue.

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?

wigga please
Nov 1, 2006

by mons all madden

geeves posted:

Any collection should do.. have you tried using <logic:present> to see if it's been loaded / available? Are you able to access the Collection with JSP instead of struts tags? Also, just a quick check - you are including the logic taglib, right? That last one has lead me to many headaches over time.

http://struts.apache.org/1.2.9/userGuide/struts-logic.html#iterate


As for the second, yes, at my old job we loaded everything into the session scope on success of the Action.

ty, got it working now, something was going wrong in the controller part, making it just return a new collection instead of the one from the model

Buster
Sep 1, 2009

Buster fucked around with this message at 05:45 on May 13, 2010

crazyfish
Sep 19, 2002

Buster posted:

I'm trying to remove the code repetition in Entry<E>'s add method, but I don't know why it doesn't work. Looking at the debugger, it seems that the changes I'm making to 'child' in recursiveTreeBuild() aren't affecting the actual child I passed in. Is there any explanation for this? I commented out the code that works.

The reason it isn't working is that when you pass in child to the method, you're actually making a copy of the reference to the child that is passed in, not the child itself. So when you reassign child within the method, you're actually reassigning a different child than you pass in (because the reference was copied when it was passed in).

Example:

code:

void foo(String e)
{
   e = new String("foo");
}

void print()
{
   String str = new String("foo2");
   foo(str);
   System.out.print(str);
}

Calling print() would output "foo2".

crazyfish fucked around with this message at 21:33 on May 10, 2010

Crazy RRRussian
Mar 5, 2010

by Fistgrrl
What happens when you use array in generic classes or functions?

What I would like to do is set key to my map as reference to array so I do something like:

code:
Map<double[],double> mem = new HashMap<double[],double>();
However size of my program blows up and I suspect it is because the whole array may be being copied to HashMap? How would I set reference to an array as a key?

If I was to do same thing in C++ I would do
code:
map<double*,double> mem;
EDIT: I am doing this in order to memoize some of my function that work on vectors. The vectors or just double arrays I pass to them do not change, so I could potentially optimize my performance if i memoized them.

Crazy RRRussian fucked around with this message at 21:51 on May 10, 2010

crazyfish
Sep 19, 2002

LockeNess Monster posted:

What happens when you use array in generic classes or functions?

What I would like to do is set key to my map as reference to array so I do something like:

code:
Map<double[],double> mem = new HashMap<double[],double>();
However size of my program blows up and I suspect it is because the whole array may be being copied to HashMap? How would I set reference to an array as a key?

If I was to do same thing in C++ I would do
code:
map<double*,double> mem;
EDIT: I am doing this in order to memoize some of my function that work on vectors. The vectors or just double arrays I pass to them do not change, so I could potentially optimize my performance if i memoized them.

I believe Java already does what you're intending to do, because the hashCode and equals methods of an array primitive already use object identity. See this link: http://stackoverflow.com/questions/1058149/using-a-byte-array-as-hashmap-key-java. If you wanted identity in the map based on array content, you would need to write a wrapper class which uses Arrays.hashCode and Arrays.equals for hashcode and equals on the array contents.

While the example uses byte arrays I believe this would apply to double arrays as well. Are you sure you're not just allocating too many arrays or trying to remove entries from the map which aren't the exact same array references as the keys in the map?

crazyfish fucked around with this message at 22:00 on May 10, 2010

Crazy RRRussian
Mar 5, 2010

by Fistgrrl
EDIT: Ok so I am playing around with Java threading and ran into this weird problem:

code:
synchronized (THREAD_DONE)
					{
						++THREAD_DONE;
						if( THREAD_DONE == NUM_THREADS)
						{
							THREAD_DONE.notify();
						}
					}
It throws exception on THREAD_DONE.notify(); which JDK tells me is when current thread is not owner of the object. However, i have the synchrnoized block right there, that should acquire the monitor for THREAD_DONE?

Crazy RRRussian fucked around with this message at 23:47 on May 10, 2010

crazyfish
Sep 19, 2002

LockeNess Monster posted:

EDIT: Ok so I am playing around with Java threading and ran into this weird problem:

code:
synchronized (THREAD_DONE)
					{
						++THREAD_DONE;
						if( THREAD_DONE == NUM_THREADS)
						{
							THREAD_DONE.notify();
						}
					}
It throws exception on THREAD_DONE.notify(); which JDK tells me is when current thread is not owner of the object. However, i have the synchrnoized block right there, that should acquire the monitor for THREAD_DONE?

I think your culprit is autoboxing. THREAD_DONE.notify() would autobox THREAD_DONE into an Integer which would be different than the primitive you're synchronizing around.

Also, are you trying to basically reimplement a CountDownLatch? http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/CountDownLatch.html

crazyfish fucked around with this message at 00:18 on May 11, 2010

Crazy RRRussian
Mar 5, 2010

by Fistgrrl
Yea something like that. But after some perusing in that package I think CyclicBarier should be more appropriate for my problem.

What I basically want is just to parallelize a loop in a function that gets called a lot from main thread. This function works on large chunks of data and is trivially paralizable (i.e. no synchronization required for computation).

EDIT:

Hmm. Well what is a good way to make all threads wait in beginning of infinite loop until my main thread sends them a message?
I tried doing notify() and wait() on another object but I seem to be getting a dead lock somewhere :(

Crazy RRRussian fucked around with this message at 00:38 on May 11, 2010

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
This entire code snippet is confused, and not just because it's apparently reinventing a library class. Variables do not have monitors. Objects have monitors. THREAD_DONE is apparently of type Integer (or Long or something; the point is that it can't be int because you can't synchronize or call methods directly on a primitive, even with autoboxing). So when you synchronize on THREAD_DONE, you're synchronizing on the monitor associated with the object currently stored in that variable.

That said, crazyfish's diagnosis is correct: ++THREAD_DONE is compiled as THREAD_DONE = Integer.valueOf(THREAD_DONE.intValue() + 1), so you're notifying on a different object than you synchronized on.

Synchronizing on an Integer object is a terrible idea, by the way, because they're sometimes shared throughout the program, so that you can accidentally have completely unrelated pieces of code competing for the same monitor by coincidence and without knowing about it, which is a recipe for deadlock. In general, classes should be synchronizing on objects they themselves allocated and that only they can see.

Crazy RRRussian
Mar 5, 2010

by Fistgrrl
Is there a non-reentrant lock in Java?

God knows, I implemented poo poo like this easily in pthreads with non-reentrant mutexes.

EDIT: Pretty much my idea is to have each helper thread acquire a lock twice on non-reentrant lock in beginning of infinite loop. Then the main loop unlock each thread's lock allowing it to do one iteration of the loop until it tries to acquire same lock two time again.

Crazy RRRussian fucked around with this message at 00:55 on May 11, 2010

Crazy RRRussian
Mar 5, 2010

by Fistgrrl
Alright I seem to have gotten around my problems with using ThreadPoolExecutor and CountDownLatch. This link proved to be helpful: http://www.javamex.com/tutorials/threads/ThreadPoolExecutor.shtml

EDIT: Sweeeeeeet my program is almost 2x faster now with 2 helper threads. Gonna try it on 8 core machine now :D

Crazy RRRussian fucked around with this message at 01:16 on May 11, 2010

geeves
Sep 16, 2004

Does anyone have any recommendations for a solid and free / inexpensive code profiler? Perhaps one that's a plugin for eclipse?

epswing
Nov 4, 2003

Soiled Meat
nevermind...

crazyfish
Sep 19, 2002

geeves posted:

Does anyone have any recommendations for a solid and free / inexpensive code profiler? Perhaps one that's a plugin for eclipse?

My personal favorite profiler that I use is jProfiler, however whether or not it will work for you depends on your definition of inexpensive. An academic license is $200 and a full license is $500.

geeves
Sep 16, 2004

crazyfish posted:

My personal favorite profiler that I use is jProfiler, however whether or not it will work for you depends on your definition of inexpensive. An academic license is $200 and a full license is $500.

Thanks,

We're a non-profit, and might be able to qualify for an academic license.

I've never been the one to set up the profiler before and with only 2 other developers most is falling on my shoulders since the they are pretty much new to Java and my boss is paranoid about performance and potential memory leaks coming from a C/C++ background.

digital-entropy
Apr 21, 2002

geeves posted:

Thanks,

We're a non-profit, and might be able to qualify for an academic license.

I've never been the one to set up the profiler before and with only 2 other developers most is falling on my shoulders since the they are pretty much new to Java and my boss is paranoid about performance and potential memory leaks coming from a C/C++ background.

I don't know if it helps but my company just released a free version of our Java troubleshooting tool. You can download it at http://www.appdynamics.com/free. It probably won't help you with the memory angle but you might get some good performance help from it.

LakeMalcom
Jul 3, 2000

It's raining on prom night.
I've heard good things about YourKit. They have a 15-day trial that may let you get what you need done.

http://www.yourkit.com/home/index.jsp

Luminous
May 19, 2004

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

mister_gosh
May 24, 2002

I have a pretty basic question, I think.

I have an object (dto - just has a bunch of getters and setters) that I'm passing to a servlet, I want to convert the request back to the DTO object. I tried getInputStream but that didn't work. I also tried casting the request, but that didn't work (class cast exception, I was sort of expecting that).

How can I get this object back?

code:
runServlet(Request dto,Response response) // this is actually pseudocode
code:
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
   DTO dto = (DTO)request;
   //ObjectInputStream in = new ObjectInputStream(req.getInputStream());
   //dto = (DTO) in.readObject();
   //in.close(); 
}

mister_gosh fucked around with this message at 03:21 on May 14, 2010

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
How are you actually sending the object to the servlet?

If you are doing it from an HTML formm you pass each one of the fields in the object as an http parameter and then get them back out using the getParameter method of the request object. This is obviously tedious and is one of the main reasons you use a framework to do this mapping automatically.

mister_gosh
May 24, 2002

MEAT TREAT posted:

How are you actually sending the object to the servlet?

If you are doing it from an HTML formm you pass each one of the fields in the object as an http parameter and then get them back out using the getParameter method of the request object. This is obviously tedious and is one of the main reasons you use a framework to do this mapping automatically.

There's a crap-ton of multi-leveled data in the DTO so I can't send as params.

I just realized that the first param to sendRequest (com.google.gwt.http.client.RequestBuilder) is a String only(?). Maybe I'm limited here afterall...


code:
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,link);
builder.sendRequest(null, new RequestCallback() {
   public void onError(Request request, Throwable t) {}
   public void onResponseReceived(Request result,Response response) {
}

RitualConfuser
Apr 22, 2008
Not sure exactly what you're trying to do, but have you tried just serializing the DTO on the client side, sending it to the servlet, the deserializing it on the server side?

Colonel Taint
Mar 14, 2004


geeves posted:

Does anyone have any recommendations for a solid and free / inexpensive code profiler? Perhaps one that's a plugin for eclipse?

TPTP has been great for the project I've been working on over the past few months: http://www.eclipse.org/tptp/

It's a bit more memory intensive than VisualVM, but can also give you a bit more detail about what's going on with certain things. Stack traces in the thread visualizer = win. If you're worried about memory leaks, it can also give you allocation details for each type of object.

Colonel Taint fucked around with this message at 04:25 on May 14, 2010

mister_gosh
May 24, 2002

RitualConfuser posted:

Not sure exactly what you're trying to do, but have you tried just serializing the DTO on the client side, sending it to the servlet, the deserializing it on the server side?

Not sure how, perhaps that's what I'm lost about (how to send data to the servlet that is not string or param based).

RitualConfuser
Apr 22, 2008
Assuming the DTO is Serializable, the basic idea is:

On the client side:
code:
// serialize the DTO

ByteArrayOutputStream bOut new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bOut);
out.writeObject(dto);
out.flush();
byte[] buff = bOut.toByteArray();

// setup the connection to the servlet

HttpURLConnection conn = (HttpURLConnection)(new URL(...).openConnection());
conn.setRequestProperty("Content-Type",
    "application/octet-stream");
conn.setRequestProperty("Content-length",
    Integer.toString(buff.length));
conn.setUseCaches(false);
 
//send the data

dOut = new DataOutputStream(conn.getOutputStream());
dOut.write(buff);
dOut.flush();

// use conn.getInputStream() to get the response
Then in the Servlet:
code:
DataInputStream dIn = 
    new DataInputStream(new BufferedInputStream(req.getInputStream()));
byte[] buff = new byte[req.getContentLength()];
dIn.readFully(buff);

ObjectInputStream in = 
    new ObjectInputStream(new ByteArrayInputStream(buff));
DTO dto = (DTO)in.readObject();
I left out all the error handling and closing stream/connections but that's the basic idea.

mister_gosh
May 24, 2002

RitualConfuser posted:

Stuff
Thanks! I will give it a try!

Partyworm
Jul 8, 2004

Tired of partying
Rookie programmer here, just playing around with I/O for the first time.

Any ideas why BufferedReader is only reading the first line of johnny.txt ?

code:
 public void actionPerformed(ActionEvent event) {
        Object source = event.getSource();
	if (source == newLine)
            try { FileReader look = new FileReader("johnny.txt");
		  BufferedReader buff = new BufferedReader(look);
		  String line = buff.readLine();
		   output.setText(line);
            }
          // other stuff
Basically i just want it to read one line from the document each time a JButton is pressed and then output it to a text area object. I kind of assumed hoped the stream would stay open until i specifically close it or it reaches the end of the file and that each button press would cycle one line at a time through the text file. I'm guessing what's happening though is each time the action event occurs, the file stream is being re-opened. In which case, how do i go about seperating the opening up of the stream from the calls to read a new line, within the context of an action event?

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Partyworm: Every time an event is fired, you create a BufferedReader attached to a FileReader, read a line, display that line and then your BufferedReader falls out of scope, so it is closed.

The simplest way to fix this is to store the BufferedReader as an instance variable in the surrounding class, initialize it in the constructor for that class and then just do "output.setText(buff.readLine());" in the event handler.

Internet Janitor fucked around with this message at 19:20 on May 15, 2010

Crazy RRRussian
Mar 5, 2010

by Fistgrrl
Can somebody recommend some Java frameworks for cluster/distributed computing? Also is there RMI service for Java that is implemented underneath using MPI?

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

Internet Janitor posted:

your BufferedReader falls out of scope, so it is closed.
Whoah, that's not what's happening. Maybe, someday, if BufferedReader/FileReader/whatever-else-is-in-the-hierarchy has a finalize() method that calls close(), that'll happen at an undetermined time. Your suggested solution is right, though.

lewi
Sep 3, 2006
King

Partyworm posted:

Rookie programmer here, just playing around with I/O for the first time.

Any ideas why BufferedReader is only reading the first line of johnny.txt ?

code:
 public void actionPerformed(ActionEvent event) {
        Object source = event.getSource();
	if (source == newLine)
            try { FileReader look = new FileReader("johnny.txt");
		  BufferedReader buff = new BufferedReader(look);
		  String line = buff.readLine();
		   output.setText(line);
            }
          // other stuff
Basically i just want it to read one line from the document each time a JButton is pressed and then output it to a text area object. I kind of assumed hoped the stream would stay open until i specifically close it or it reaches the end of the file and that each button press would cycle one line at a time through the text file. I'm guessing what's happening though is each time the action event occurs, the file stream is being re-opened. In which case, how do i go about seperating the opening up of the stream from the calls to read a new line, within the context of an action event?

You're kind of correct - each time the action event occurs, you're making a new FileReader, BufferedReader and String to display. Internet Janitors fix will work.

Parantumaton
Jan 29, 2009


The OnLy ThInG
i LoVe MoRe
ThAn ChUgGiNg SeMeN
iS gEtTiNg PaId To Be A
sOcIaL MeDiA sHiLl
FoR mIcRoSoFt
AnD nOkIa

LockeNess Monster posted:

Can somebody recommend some Java frameworks for cluster/distributed computing? Also is there RMI service for Java that is implemented underneath using MPI?

No idea of MPI solutions but for clustering applications Terracotta is quite popular. It also works nicely with OSGi which should help you further in modularizing your app.

If you want to cluster a specific subset of your program such as data processing, you may want to take a look at Apache Hadoop which is a Map/Reduce based framework for data processing.

Crazy RRRussian
Mar 5, 2010

by Fistgrrl

Parantumaton posted:

No idea of MPI solutions but for clustering applications Terracotta is quite popular. It also works nicely with OSGi which should help you further in modularizing your app.

If you want to cluster a specific subset of your program such as data processing, you may want to take a look at Apache Hadoop which is a Map/Reduce based framework for data processing.

Cool thanks!

What I am trying to do is high performance bioinformatics computation on a super computing cluster. Perhaps java is not right solution but I think it could offer nice tradeoff between scalability and ease of the overall design versus the actual speed.

Thank you for those links I will research those solutions and see if they are appropriate for my problem.

Parantumaton
Jan 29, 2009


The OnLy ThInG
i LoVe MoRe
ThAn ChUgGiNg SeMeN
iS gEtTiNg PaId To Be A
sOcIaL MeDiA sHiLl
FoR mIcRoSoFt
AnD nOkIa

LockeNess Monster posted:

Cool thanks!

What I am trying to do is high performance bioinformatics computation on a super computing cluster. Perhaps java is not right solution but I think it could offer nice tradeoff between scalability and ease of the overall design versus the actual speed.

Sounds like a job for Hadoop distributed processing jobs so definitely worth checking that one out.

Adbot
ADBOT LOVES YOU

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
I'm writing a really simple IRC bot just to learn poo poo and I'm trying to do something. I don't know what it's called. This is frustrating me. (i am bad at java/programming)

Strings have methods like contains and substring and poo poo, so I can do:
code:
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
	String inputLine;
	while ((inputLine = br.readLine()) != null) {
		if (inputLine.contains("End of /MOTD")) {
			break;
		}
	}
but if I want to do poo poo like
code:
if (inputLine.isFrom("AlekseiV")) {
	//A message from the bot owner!
	doShit();
	}
how do I create the method isFrom() for strings? help :saddowns:
A tutorial or way of doing something similar or even just Google search terms would be great since I have no idea wtf this is called

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