~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You have already established that the 'disconnect after certain idle time' setting works for bonecp. Now you need to analyze your code to see why is it taking up multiple connection objects for a single request (assuming that what's happening here). You don't need 4 test clients for this. Fire up your app and without sending across requests check how many connection objects are created. After that just send across a single request and then check how many connection objects you have.

It's quite possible that bonecp initializes all the connections eagerly resulting in a full pool. So basically from this point it's either:

  1. Your app isn't releasing connections in a timely manner
  2. Your bonecp configuration is causing the eager initialization of the entire pool
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The error message suggests that you are running out of ports on your local Windows box which kind of seems strange given that you are just sending across 4K requests. Anyways, now that you are sure that there are no leaking connections, there isn't a need for this stress test client.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Don't post the leak results, just check the instance count for Connection objects. If after 30 mins of idle time, the leak report doesn't show any Connection objects, we are good. The error you posted is because you are creating too many client connections in a short amount of time. Why can't you just use the same socket connection for sending across multiple requests?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I haven't really worked with JavaMail before but I can provide a few generic comments.

This thread mentions that Transport.send creates a new connection everytime. You should create the session and transport object just once (maybe create a class EmailSender), and use them to send all your messages.

Also I think we are getting offtopic here; if you have more questions which are not related to your connection pooling issue, create a new thread.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

If you don't see Connection objects hanging around after idle time (30 mins), you are good.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Adjust the loop iteration count based on how many times or how long you want to run the test. And yes, just one loop should be enough.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

They will execute simulataneously because you are executing 4 of them and they are running independently (assuming you have enough free cores). If you have spare machines, just execute the program from multiple machines to get true parallel execution.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

If you have a handy link to some suitable reference I'd appreciate it, if not don't worry, I'll find it myself.

The reason is that hyphen (or dash) character has a special meaning when used inside a character class (i.e. stuff between the square brackets) which is basically specifying the character range. You can get around it by either specifying it as the first or the last character in the character class or escaping it with a backslash. I can't find a definitive reference but this SO link covers the material in a pretty good way.

But, including it at the front or end looks cleaner

Agreed, especially given that Java doesn't have raw strings. ;)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Just ensure that if you need to replace the literal -, it is always either at the start or at the end of the replacement set. For e.g. txt.replaceAll("[- _?]", "*") works, txt.replaceAll("[ _?-]", "*") also works but txt.replaceAll("[ _-?]", "*") doesn't.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It just means create multiple processes. For e.g. open up three/four consoles/shell and do:

   java -cp . com.yourpkg.YourTestCode

in each of them. Now you have 3 Java instances running the same code and hence simulating simultaneous requests to your app. Unfortunately I can't simplify it more than that.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Below is what I plan to run for the stress test. What is your opinion? I feel is not parallel enough.

That piece of code isn't parallel; just extending Thread won't make it parallel/multi-threaded. If you want to keep it simple, I would recommend running the same program multiple times (thereby creating multiple processes) to simulate multiple simultaneous clients.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Should I like create a client which makes multiples connection at one
go. The issue is that I can just run one for loop and make the many
socket connection but is serial connection? How to make parallel
connection from one machine ? I would like to hit it as hard as
possible.

There are specialized frameworks/toolkits out there to carry out stress testing (JMeter being one of them). Anyways, if you want to go the simplest route, you'll have to create multiple clients which hit the server. This can be done by creating threads (each thread will perform a request, possibly in parallel if you have multiple cores available) or by spawning multiple Java client processes.

Do you what is the default setting for idle close setting for bone cp?

I don't know for sure but this thread implies that it's 60 minutes. To confirm you really are leaking connections, set the max age to 30 mins (look at this post for config settings), stress test your application, take the snapshot, leave it idle for more than 30 mins, then again take the snapshot. If you still see connection objects hanging around, either the connection timeout isn't working or you are not returning connection objects back to the pool.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

When you say stress test how to perform in my case ? Should I make lots of socket connection in one minute ?

Yes, stress test is basically hitting your app as hard as you can with requests to exercise/know its limits. In you case you can spawn multiple threads from a test computer (or from multiple computers) and send across requests..

I am using Bone cp and I just saw there is idle close setting which I am not too sure what to set either?

It normally depends. In some cases, there is no problem with having 10-20 connections open to ensure that there is no connection creation overhead when a new request comes in. In some cases, open connections for a long time are not feasible and you can live with the overhead of creating new connections when requests come in after a long idle period. For a low profile application, start with something like 30 minutes and tune accordingly as per your application usage patterns.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

24 hours doing what? Are you doing any sort of stress testing in those 24 hours? Memory is not the problem here but unclosed connections is. The simplest way to check whether the connections are really "leaking" is to stress test the application. If you are not closing connection object, you will eventually run out of them. If you are not running out, you have got a problem with your pool configuration which isn't closing idle connections.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It's just a leak "suspect" report and not a "sure-shot" leak report. What was the time interval between taking the two snapshots? If that time interval was less than the time for which BoneCP waits before closing an idle connection, you are bound to see connection objects hanging around.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The total memory occupied by those JDBC connection objects looks to be around 12 MiB. You have 40 connections as the max connection count per partition. Which observation leads you to the conclusion that those are not pooled connections but "jdbc leaks"?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

When I say the "throw clause" I mean something like

Don't call it "throw", call it "throws" clause. You use throw when you want to throw a new exception i.e. create an actual exception object. Something like:

public void transfer() throws TransferFailedException { // this is the *throws* clause
    if(account1.transferTo(account2).hasFailed()) {
      throw new TransferFailedException(); // this is the *throw* clause
    }
}

and be able to say something like "Oh ok, so nextInt() can't have a throw clause the same way as the intDivide() method can"

Generally speaking, the possible exceptions thrown by a method are documented in the Javadoc. If it's not in the Javadoc, you have no easy way of knowing all the possible exceptions a given method can throw except for diving deep into the source code. For e.g. a lot of standard library methods can throw a NullPointerException if presented with a null input but don't mention it in the Javadocs like Pattern.compile.

So to conclude, just hop over to the Javadocs for finding exception related information for a given method or use an IDE which provides all the details. If a method throws a "checked exception", the compiler will anyways warn you (by asking you to either handle it or propagate it up the call-stack).

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Firstly, read this: checked v/s unchecked exceptions

in line 10 the method quotient throws an exception that will be caught by the catch statement

Wrong phrasing; there is a possibility that the method quotient might throw an exception. When a method has a throws clause, it means that the method might throw that particular exception (you can have multiple exceptions but you get the point). The most confusing part with exceptions is that when you are dealing wiht unchecked exceptions (i.e. exceptions which extend the RuntimeException class), you are free to omit the throws declaration when defining methods. But, the important point is that the method can still throw an exception. As an example:

public int intDivide(int a, int b) {
  return a / b;
}

public int intDivide(int a, int b) throws ArithmeticException {
  return a / b;
}

Take a look at the methods defined above; what difference do you see? The only difference is that the second method explicitly mentions/states/informs the method consumer/user that intDivide can throw an exception. Notice that all this is orthogonal to the fact that both of them will throw an exception when passed b=0. It's just that the second method mentions it explicitly but the first one doesn't. Why is this possible? Because ArithmeticException is an uncheked exception.

Now let's consider the example of a checked exceptions:

// invalid
public int readFromFile(InputStream in) {
  return in.read();
}

// valid; works
public int readFromFile(InputStream in) throws …
iamthwee commented: solid +14
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I'm going to leave it as is for now, but track its usage, and please let me know how often you guys find yourself using it.

Dani, I would really suggest at least providing a tooltip for the green arrow, something like (Spellcheck + Preview) or provide a "Help" link to its right which shows what the different editor options do. I click on the green arrow a few days back but since I didn't have any spelling mistakes, I assumed it was just for toggling editor preview.

Octet commented: I thought the same thing, it was only after seeing this that I realised it was a spell checker as well. +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hello Lena, good to hear that you have solved it given that I had pretty much run out of suggestions. Regarding:

Select the language, and then click OK.

I'm curious; what was it before on the user's PC and what did you change it to?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

do you think that i should install java FX Ensumble(Native) 2.2 on the user computer and run the program

Don't think that should make a difference but you can try it out. Did you check that the user's computer actually supports Arabic? Send across an arabic text file and open it up on the user's PC to check it out.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

i use this way it changes the writing from ???? to something like this áÊÇá so i am thinking could i use something other than Cp1256 and utf-8 ???

Nope, unfortunately it doesn't work that way.

or the problem could be in the jdk and jre i use ???

Don't think so. But for the sake of completeness, can you post the Java version and which Windows OS / Office version you are using?

Also, reply to the questions I posed in my previous post and try out the properties thing I mentioned.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

There isn't much I can do sitting here unfortunately. One last thing you can try is to explicitly set the encoding when getting the connection. I'm assuming you are using JDBC-ODBC bridge driver. Put the following key-value pair in properties before passing it to getConnection: prop.put("charSet", "Cp1256"); or prop.put("charSet", "utf8"); as mentioned here.

EDIT: Also, are you sure Arabic characters can be displayed on the user's computer? How are viewing this data on users computer (i.e. directly in MS Access or in some application which you have written)? Can you send across a text file containing arabic data to the user's computer and check if the user can actually view it?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

@David: I just tried posting your new snippet in the original post but it still doesn't work.

@Dani, this is something to look into. You can reproduce this by trying to update David's original code snippet based on his latest post.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

If you can post the entire code once again in your code snippet thread, I can update your original post.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Your question isn't very clear; can you provide a sample input/output for the use case in consideration?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

When does this happen; when you run it on the user's PC or on your PC? If you are trying this on your user's PC, can you also try it on your PC? Also, print out the method output for the methods mentioned here in both the cases.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

how can i pass the -Dfile.encoding=Cp1256 when starting up Java process.

How does the user currently open up your application? I'm assuming via a .bat file? The idea is to modify the Java command line used. For e.g. if your command line is java -jar SomeAppJar.jar, then modify it to something like java -Dfile.encoding=Cp1256 -jar SomeAppJar.jar.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Have you tried out the JAVA_TOOL_OPTIONS trick? It doesn't matter whether you add it to the user or the system variable tab. Also read the original link I posted thoroughly so that you know what should be the value for JAVA_TOOL_OPTIONS.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

thanks for replay but i open environment variable but i couldnot find the JAVA_TOOL_OPTIONS variable do you want me to add it to the user variable or to the system variable ???

Yes, you'll need to create this entry. If this doesn't work out, try passing -Dfile.encoding=Cp1256 when starting up Java process.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The real solution would be to manage the encodings explicitly (preferably using UTF-8) when inserting/querying db data. As a hack, you can try setting the JVM encoding using the tricks mentioned in this thread. Instead of using UTF8, use windows-1256 (or Cp1256 if it doesn't work).

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

What does System.getProperty("file.encoding") and Charset.defaultCharset() print on your and the user machine? Are the values different?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Well, that's one issue then. When you store data from your machine, the default encoding of the machine is used because of which everything works out well. But when you run your app on a machine which has a different encoding (i.e. non-arabic), you end up storing arabic data with a non-conformant encoding hence the garbage characters.

Just to confirm: can you copy over your Access DB file to the users computer and try opening it up there. Does it still show as ????

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Does your box/Windows installation have Arabic set as the default language? Are you explicitly setting any sort of encoding in your code when writing/storing data in Access?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Restlet, Jersey and Resteasy are all good REST frameworks (useful for creating RESTful web services). Read the example code/docs on their website and pick up one which works out for you.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Actually iamthwee brought it to our notice in this thread he created.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Just got confirmation back from David saying that he didn't post it that way. So it boils down to the post snippet routine doing something funny.

Dani/Decepti-kun, one for you I guess?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Can you post a clean version again so that I can update the original snippet? It would be too much work editing the original snippet.

Also, if you didn't post it that way, this is something for Dani to look into.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Is it possible for your to copy the Access DB file from that computer and open in up on your computer? Does it still show ??? or does it display the data correctly? Since you say it works on your box, this seems like a case of missing font pack/regional pack or something along those lines.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

This snippet without headers doesn't seem to have this problem. There is one more possiblity which I missed the first time: the OP might have actually posted the HTML escaped code snippet. I have posted a comment on that snippet thread; let's see what he has to say.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

David, it seems that your < and > have been turned into &lt; and &gt; respectively. Did you post it that way? If not, I'll have to ask Dani to look into it.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

How does visualvm get it's info (eg number of instances awaiting finalisation)? Maybe there's no way from within the language, but what kind of instrumentation interface does visualvm hook into?

That's a good observation.

First to clarify: the number of objects pending finalization isn't really the same as the number of objects eligible for garbage collection. The former means that the objects are already identified as part of garbage (or simply put have been GC'ed) and have been put in the finalizer queue by the GC. The latter asks the question "when the next GC cycle runs (minor or major), which objects would be picked up for GC".

Secondly, it's easy to get the number of objects pending finalization; we already have a MBean for it. There is a catch though; that count is only for objects which have a non-trivial finalize method i.e. is only applicable for classes which override the finalize method. Since the OP (I believe) has no control over the objects, this count would not reflect objects of custom classes which don't override finalize. So I would say that count is not a very good measure in this particular case.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The problem I believe is that special characters like < and > don't require conversion to their HTML entity counterpart when placed inside a pre since the rendering engine just "literally" evaluates them as opposed to recognizing the sequence and rendering it as the corresponding special char. Daniweb code snippet handling code seems to be converting the special chars to HTML entities which is not really required.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I am trying to write a program which will help me find the number of objects eligible for garbage collection at any given point of time

AFAICT, there is no mechanism exposed by the JVM to "count" the number of objects eligible for garbage collection since this would in turn require a "mark" cycle.

Can you avoid that problem by using only weak references?

Unfortunately none of the reference types (phantom/weak/soft) will help here.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It functions more like an IDE than a textbox. You can tab to indent, shift+tab to go back a tab, etc. It's all color-coded so you can easily see where a link is, what is considered code, etc. None of that is possible with a regular textbox.

I believe if we keep a poll to decide between whether to have a spellchecker or whether to have the "tab"ing functionality, spellchecker would win. :)

I have access to moderator tools on both Daniweb and SO and I don't think editing on SO is any more difficult than editing on Daniweb.

That's because SO takes the approach of quickly and cleanly deleting every post that is formatted incorrectly

I'm afraid this isn't true. Spam posts are deleted and trivial/frequently asked/vague questions are closed. But if a post has good content but is formatted incorrectly because the OP doesn't know how to use Markdown or has messed up, the community takes care of formatting the post for the OP. If I'm not mistaken, there is a metric which keeps track of how many meaningful edits you have made but that's just part of the SO number game.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Have you tried the zip command?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

If Bjarne Stroustup himself joined and wanted to endorse me for C++ but couldn't because he didn't have enough up votes, I'd be a little miffed. ;)

Haha, nice one. :) But I guess you misunderstood me. What I was trying to say is that when a forum member wants to endorse someone, that particular someone should have a minimum of 'X' number of up-votes in that forum.

But I hear you; it's really just another subjective metric though I personally feel it should stop the abuse wherein those who really shouldn't be on the endorsement list end up on it.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Maybe endorsements should be limited to only those members who have made XXX number of posts in a forum

I would say make that "X number of up-votes" in a particular forum. That would be a more balanced stat since it's really easy to have a good number of posts in a given forum (piggybacking on good answers, asking lots of questions etc.) but not easy enough to gain reputation/up-votes. I mentioned up-votes instead of reputation because reputation is far difficult. Anonymous voting is what most of the folks like these days.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I just thought that, given the fact that not everyone tags their posts, a specialized forum might help on keeping those threads organized in the database general forum.

Well, the idea is to encourage everyone to start tagging their posts. If the users/posters don't themselves tag it, you can flag it as a bad post as one of the moderators will do the tagging. This should hopefully increase the "tag" adoption since with new technologies coming in so quick, one forum per topic model is very difficult to maintain. There are two ways in which websites are dealing with this; some boards/sites just have a blanket sub-forum for dealing with topics. For e.g. they would have a forum called "programming langages" which can contain query for any programming language. Other forums (notably SO) have gone the tagging route which makes it so much easier to filter/organize content.

Daniweb has gone the hybrid route; should be interesting to see how this pans out. :)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

so in a multithreaded program if i had my song class that was shared between two or more classes then they could possibly both have the ability to change song objects. then this could lead to the program not functioning correctly. If you have time and don't mind making an example I would love to see it.

It need not be a multi-threaded program. Mutation related bugs can slip in even for a single-threaded program though they are normally more painful and hard to find in case of a multi-threaded one.

As an example, let's say that you plan on providing a "replace" functionality to your users of the playlist class. So basically, they can pick an existing song from the playlist and replace it with a new one. If you resort to mutation (to save memory as they all say) and instead of creating a new song, try modifying the existing song, this is what happens:

MP3_Player ipod = null; // initialize with songs; assume
Song toRemoveSong = ipod.getSongByName("Hotel California");

// we need to maintain a list of removed songs
List<Song> removedSongs = new ArrayList<Song>();
removedSongs.add(exisingSong);

// In some other method; try replacing the song
Song oldSong = ipod.getSongByName("Hotel California");
oldSong.setTitle("Baby");
oldSong.setArtist("Justin Bieber");

// Show the songs user has removed from the ipod
showToUser(removedSongs);

In case you haven't noticed yet, we are hosed. Since Song is mutable, the list of removed songs now contains 'Baby' instead of 'Hotel California' and you have lost the song …

nova4005 commented: Thank you for the great examples +1