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

AFAIK, "the same" is a common way of referring to a previously explained/mentioned context. For e.g. compare and contrast the following two sentences:

I've upped the servers on the production box; please monitor the same for at least two days.
                                              v/s
I've upped the severs on the production box; please monitor them for at least two days.

It seems that this use of "the same" doesn't quite seem natural to native English speakers. I personally don't think it is technically/grammatically wrong, but if you think it is, feel free to enlighten me. :-)

EDIT: humour

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

I wouldn't delete the whole code just most of it since most of it was meaningless to post. My WHOLE program was copied and pasted, then I realized I didn't have to have the whole world see my entire code, just a few lines would have sufficed.

Been there, done that.

Editing posts on demand to remove confidential information (your university portals credentials) is a different thing. Selectively editing posts to remove pieces of code/content is full of gotchas and a real pain in the neck.

There was one occurrence wherein a member requested one of the mods to *selectively* remove images from his post and keep the other things intact. Later, we came to the realization that the entire question looked meaningless without the images. Selectively editing posts requires us to coordinate with the member in consideration to get the post which *he* wants to see, then making sure that what *he* wants is really feasible and doesn't make the thread lose its meaning and so on. In short, too painful to be done as a favour (since the rules anyway don't allow it).

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

If you ask really really nice you might ask one of the mods to remove the code you posted, leaving the rest of the post.

That would be a wrong thing since removing content from posts which don't violate any rules would be against the rules. I do admit that in the past we had occurrences of moderators removing *things* from posts/threads so that the OP doesn't get caught but that was because that particular moderator wasn't aware of this rule.

Also, removing the code from a programming thread kinda makes it meaningless, no? :-)

How do I contact one of them?

Contacting the moderators won't help; read my reply above. Your best bet would be to convince your teacher that you have put in your own hard work when creating this program and give him/her the thread URL so that you can be in the clear.

(but Ezzaral is a moderator, so you've already talked to one, just sayin')

The moderators can edit posts/threads only in their given jurisdiction and AFAICT, Ezz isn't a moderator of the Java forum. ;-)

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

Yes, just put the entire client server communication in a loop. Also, make sure you read the output from the server to ensure that you are getting the correct result.

Regarding the database, every database server has a configuration wherein you can configure the maximum number of connections allowed. Plus, it also allows you to view the total number of database connections in use at any given point in time. Look into these two things for your MySQL installation or ask your DBA. This is necessary to determine whether there is a connection leak or the maximum allowed connections is really low for your application.

Before running the test, make sure that the code changes to the server which I suggested are in place (closing 'r' and client socket).

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

Why is it hanging is because I did not close my telnet terminal.

IMO, testing this with a standalone Java client would be much more efficient since in that case you can also test multiple client connections in a loop. The code would be as simple as opening a socket to the server, sending data to server, reading it and closing the socket. This kind of test can also be run from your *local* machine (local windows box).

So this time I will open the telnet terminal send data and close the terminal ok or you want me to leave the terminal open. Give me some time to prepare for all this.

No, when I say test a client connection to your server, you should make sure that is a normal communication. Client sends a request, server responds to that request, client exits and server continues to serve other clients. That way we can be sure that the client has disconnected, the server has moved on to a new client and any more resources used by the server are resource leaks.

Besides that I have increase the ulimit to 2048 and this have done some help today.

Yes, if nothing, it would at least delay the occurrence of that IOException.

[root@localhost /]# netstat -nat |grep 9000 | awk '{print $6}' | sort | uniq -c | sort -n
1 LISTEN
5 SYN_RECV
7 LAST_ACK
16 CLOSE_WAIT
275 ESTABLISHED

BTW, what exactly is …

kvprajapati commented: Good discussion. Learn something new. +11
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

OK, now we are getting somewhere. Why is there is established connection hanging around even after 5-10 mins?

java 3610 root 8u IPv6 15008 TCP 192.168.2.15:webcache->63.92.48.60.kmr02-home.net.my:55006 (ESTABLISHED)

Now, three more things:

  • Find out what exactly that connection stands for. AFAICT, it seems to be "socket" opened by the server as part of "accept()" but just make sure it isn't something else again by talking with your admin.
  • Do the same test, but with continuous 10/20 clients. Make sure you *restart* the server before beginning the test. If after the test we have around 10-20 established connections lying around after 10 minutes, we would be damn sure it *is* a leak.
  • If the above step shows a leak, close everything in your last "finally" statement. By everything, I mean the 'r', 'w' & 'socketConn1'. This isn't a very big change and is required because there isn't much correctness check we can do in this small code except close all open resources (which isn't happening now)
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The increased number of file handles even after the entire client-server communication is done with is a bit troubling. That shouldn't be happening.

OK, now one more test. For the time being forget about the original box since we now have a dummy server deployment which we can use for our testing. Now, instead of printing out the *number* of file handles, print out the the entire data and redirect it to a file. Steps:
1) Start the server and don't request any data for the time being
2) Do lsof | grep java > before.txt .
3) Test for connection with data being sent; preferable would be to send data from your local box so that you don't end up using the file descriptors on the server box for testing your client.
4) After a single client transaction (send/receive) is complete, wait for some time (around 5 mins).
5) Now do lsof | grep java > after.txt .
6) Compare the two files; what do you see?

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

Weak indeed. Oh wait, I thought I had already convinced you that Mitsudomoe was an awesome anime? ;)

Anyways, I would be watching at least the first episode of each anime so it should give me a rough idea as to which anime is worth watching and which isn't. There *are* a couple of animes I see here whose plot sounds different but then again I have seen too many a screwups when it comes to the realization of the plot so not hoping for a lot. :-)

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

Pick any members you find interesting and describe how you imagine them to look/act in real life.

OK, I guess I'll just describe a few members here with one liners:

Narue-chan: Someone who bullies everyone everywhere; be it a MMORPG or an interview. I've always imagined you as a woman with an evil gleam in her eye. Of course, YMMV. :-)

Rashakil: A mean geek who lives for the sole purpose of insulting lesser mortals and anyone who refuses to acknowledge Haskell. Doomed to get a doctoral in Math.

John A: I've always imagined Joey to be the next Mark Zuckerberg given his geeky nature and innate management/leadership skills.

Wolfpack: A Japanese guy who doesn't love anime, drinks a lot and lives a mysterious life. OK, maybe not the last one... :-P

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

A new anime season is just around the corner; preview here!

Kimi No Todoke 2nd season and Mitsudomoe 2nd season are on my must watch list but all in all this new season looks depressing. :-(

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

OK, my point was that deploy your application on a dev/test box and use a *dummy* client which simulates a GPS device. Surely you can do that, no? Basically it means running both applications side-by-side where one application would anyways be used by the devices as usual + the new application which you can use for testing. Don't you have a spare box running the same OS/configuration?

Also, the *simplest* hack here would be to just bump up the file descriptor limit and cross your fingers hoping that things work out. I guess the syntax is something along the lines of: ulimit -n 4096 but confirm this with your sys-admin. If there is a genuine code bug, you would get a "Too many files" error at some point in time, it's just that it would take a bit longer to reproduce it.

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

3. The exact number is 230 TIME_WAIT is when the system crash. The problem now I am monitoring with this command netstat -nat |grep 9000 | awk '{print $6}' | sort | uniq -c | sort -n. I notice when the established connection is below 200 no problem at all running for many hours with out problem. The moment I increase to say 216 then I get TIME_WAIT increase if not there is no TIME_WAIT at all shown in the command. So can this be due to the increase of clients.So must I increase the system file descriptor limit? Thank you.

OK, let's go over this again. *How* are you exactly testing this thing? Are you running the stats on your existing deployment? If so, don't do that.

Do a fresh build of your code on some dev box or some other location for the purpose of testing. Start your server. Look at the number of file handles used by all "java" processes by doing: lsof | grep java | wc -l . Look at the number of TIME_WAIT now. Lets call these numbers collected as "set 1".

After this setup is done, create a client which hits your server and requests for some data. Only a single client. Now collect the same two statistics as mentioned above (set 1). It would obviously be more than the numbers collected previously. Now wait for some time, around 5/10 minutes and check the same two statistics again (set 3).

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

AFAIK, no, not possible since a JAR file is just a zip file and is not capable of containing that sort of meta-data. This is the reason you'll notice that applications which rely on running a JAR also supply a shell script for that given platform which fires the JAR by setting the relevant options.

Solution would be to ship your JAR file with a shell script for each platform you are shipping on or use something like JSmooth which provides a thin executable wrapper over your JAR file and I think it also supports passing in JVM parameters.

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

I can't understand why s1,s2,s3 are having same hashcode although i created as strings and objects as shown

As already mentioned hashCode depends on the value of the object. Plus, when you override equals() you need to provide a logical implementation of the hashCode() method which adheres to the equals-hashcode contract.

If this were not the case, the behaviour of using Strings in any hash table based implementation would break. E.g.

public static void main(final String[] args) {
  final Set<String> set = new HashSet<String>();
  set.add(new String("HI"));
  set.add(new String("HI"));
  set.add(new String("HI"));
  System.out.println(set.size()); // how many elements does the set contain?
}

The expected count for the above code snippet is 1. If every new String instance which contains the same value returned different hash codes, the above behaviour would be violated.

This however wouldn't be a problem for collections which don't rely on hash table implementation under the hood. For e.g. if TreeSet is used instead of a HashSet in the above example, the only thing that matters would be whether the String class properly implements the Comparable interface and nothing else.

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

Actually I am also not too sure about the flow of the wrapper. I would guess that my application runs in the wrapper.jar then this application is run in the WrapperJVMMain class.

Then you need to grab someone who knows how wrapper works (the person who implemented this or maybe ask in the wrapper tool forums).

1. Why I run in wrapper is that I need the java to run as a service. So what is other solution to this any suggestion from you? The probem is that the server is in remote location so I am using putty to do all my operation.

The simplest possible option would be to spawn the process in background.

nohup java -cp .:somejar.jar -Dother=options SomeClasss &

2. What do you mean by remote debug?I am not too clear about how eclipse will help here.

You can use Eclipse to remote debug your application. So when ever a request comes, you can set a breakpoint in your server code and step through your entire code as it handles the client request. Eclipse also has the facility of attaching breakpoints for "specific" exceptions. Just add breakpoints for IOException and SocketException and you should be good to go. Search the net for tutorials for the same.

Another question why at times there is not single time_wait but suddenly the time_wait grow and crash the applcation.Is there anything causing the time_wait to happen and grow?

As per the man pages, TIME_WAIT is state is …

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

Ok I did this command and below is the results. The problem I dont know which pid is for my java application is it 3073 or 3096.

PID 3073 runs the JAR file wrapper.jar whereas PID 3096 runs the main class WrapperJVMMain. So the question is, is the code written by you packaged in the wrapper.jar file or wrapped up in the WrapperJVMMain class? That would be the answer to your question.

Regarding the stack trace, that probably means that the connection was severed/reset by the client and hence reading any more from the SocketInputStream is causing an exception.

Do you think I am lacking any close operation in my code?

Your code is a maze of if...else statements so its difficult to find out whether any connections/resources escape closure if an exception is thrown. There are now two things IMO which you can try out:
1) Run the code *without* the wrapper and see if it shows the same behaviour. Why do you require a wrapper anyway?
2) Remote debug your application. Make the necessary changes to the environment variables of your Java process, remote debug using Eclipse and you should be able to realize what resources aren't getting closed.

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

System administrators are pretty good at these monitoring things so if you can grab one to help you out, that would be the fastest route out. Using forum system for communication/debugging has a visible disconnect as you can see.

Anyways, AFAIK, more /proc/sys/fs/file-max gives you the *total* number of files handles allowed by the *OS*. It is more likely that you are hitting a per-process limit here ( ulimit -n ). Also, running just lsof | wc -l would be little use since it monitors the file handles for *all* processes visible to you. Find out the PID (process identifier) of your process using the ps ux command. Then do: lsof | grep YOUR_PID | wc -l . This would give you the number of file handles used by *your* Java process.

Regarding monitoring; you need to start the monitoring when your server process starts and look for changes when clients request services from your server. The number of used file handles *should* go up(at least by 1) when a client connects to your server. Like I mentioned in my previous post, ideally, the number of file handles free at the start of your server should be equal to the number of free file handles at any given point in time. If it isn't, then you are leaking resources.

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

1. When I run ulimit-n I get 1024. I dont get your when your run a java code keep opening and never closing it?

1024 should be good enough given that you have just 300 clients. I suspect a resource leak here given that this problem of file handles occurs after running your application for a given amount of time.
Regarding the test code, what I meant was to write a simple code which recursively traverses directory for files, opens them and never closes the file handle. Just print out a counter after opening a file. After the exception "Too many open files" is thrown, just have a look at the counter which was printed and that would give you the number of max file handles your process is allowed to create.

3. Are you saying for each of the exception I run this code w.close is it?

No, what I'm trying to say that is make sure you close *all* resources eventually, exception or no exception.

I would recommend that you carry out a small experiment: deploy your server code. Monitor the current used file handles count by your process. Hit your application with a client request. Now monitor the used handle count. Ideally it should be the same as before the server started receiving requests. If the number of used file handles keeps on proportionally increasing with the number of requests, you have a leak.

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

Basically it means that the process has reached the limit for its open file descriptors and the server can no longer accept connections from the client.

So basically now it boils down to answering the following questions:
- How much is the current limit (ulimit -n) per process? (you can also verify this by running a Java code which simply keeps on opening files and never closing it)
- How many simultaneous connections are you getting from the clients?
- Are you sure your code is written such that all resources are closed even when there is an exception?

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

AFAIK, `bind` accepts a tuple; just wrap those HOST and PORT in another pair of parentheses and you should be good to go.

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

Reason: not getting desired result. sorry I really tried.:)

You can always "view" what you have written by pressing the preview button. Given that you are learning, it would be worth it to *never* type out your responses in the "quick reply" editor (the small text area which you see at the bottom of every thread) and always use the "advanced editor" (Use Advanced Editor) button below the text area.

Pro tip: Don't try to take in all of it at once. Learn about one thing at a time. Thinking of too many things would have the end resulting of just confusing you, nothing else. Good luck. :-)

Agapelove68 commented: You are absolutely right. This was confusing me and didn't let me edit before 30 min were up. Thank you for your encouragement! :) +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

tell me if there are any other commands other than rcp and scp .

You can try `rsync`. Assuming you want to transfer files from server 1 to server 2:

rsync -avz user1@server1:/src/path/ user2@server2:/dest/path

You can ignore the user@host syntax for a particular server if you are already logged to that server. The above command basically "syncs" the files from 'src/path' directory on server1 to 'dest/path' directory of server2.

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

If memory serves me right, this is due to the "conversion view" setting of gmail. For changing it, log in to Gmail -> Settings -> General Tab -> Conversation view -> conversation view off should go the trick.

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

I think you should post the latest updated code. That way, maybe I or someone else will give it a look and if it seems like a known issue, will let you know.

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

Which browser are you using? You can try clearing the browser cache (everything related to Daniweb), log out explicitly, press CTRL + F5 on the login page, wait for the page to reload and then try again.

If cookies and Javascript are enabled, I don't see any reason why the forum shouldn't work fine for you.

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

That's not a very good implementation, without any logical overrides provided for the equals()/hashCode() method along with the instruction to not *touch* the class, the only option you have is to "inspect" the Node data. E.g. (untested):

private boolean containsItem(BTreeNode<T> current, BTreeNode<T> target) {
    if(current != null) {
        // assumptions:
        // 1. the data pushed into the tree implements logical ordering i.e. Comparable interface
        // 2. the data pushed is never null
        final int cmp = ((Comparable)current.getItem()).compareTo(target.getItem());
        if(cmp > 0) {
            return containsItem(current.getLeft(), target);
        } else if(cmp < 0) {
            return containsItem(current.getRight(), target);
        } else {
            return true;
        }
    } else {
        return false;
    }
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Thoroughly read the Javadocs of the Thread class; do you still think your answers are correct? If yes, give reasons rather than just saying "I think A,C,D are correct".

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

The regular expression: ([.,!?:;'\"-]|\\s)+ should do the trick. It is read as "for one or more occurrences of either a whitespace or punctuation". The important part here is to make sure that the '+' is kept outside the alternation, since we can have a mix of white-spaces and punctuations.

The problem with your regular expression was that you didn't take into consideration punctuations and whitespaces, but rather punctuation followed by whitespaces. If you have a 'this or that' situation, use alternation. Writing patterns one after another just increases the matching requirement; your pattern read "match any punctuation *followed* by zero or more whitespace characters" which isn't what you wanted. Hence all it did was match punctuations but blew up when faced with white-spaces.

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

You sure? Can you post the code for your BTreeNode class?

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

an Enum can be modified in the same way as the database entry, no

They can be modified, but not in the same was as you can do it for database entries. Updated database entries would be visible to the application code almost immediately (or would require flushing the cache if you are caching) but for enum related changes you'd require either a restart (in case we are talking about deployed/managed applications) or an update to client (in case of standalone applications), both of which are pretty involved tasks.

Also, depending on *what* you are representing as key-value pair, it might result in the "enum" solution totally going out of hand with a large number of entries. Also, the database solution would be a good choice if the "would be" enum you talk about would have to be in the end persisted in a database. If for your particular use case, the "enum" is part of only the application logic and not your persistence logic along with having a fixed set of values, the enum solution is a pretty good one.

As already mentioned in my previous post, there can be no black-white answer to this thing; it'd all depend on what you are dealing with though with the points I've raised, you might be better equipped with making a decision.

EDIT: Also, a common anti-patten with enums is to think of them as configurable type-safe entities. If you need something configurable, you are better off using …

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

As mentioned in my previous post, make sure that your BTreeNode class implements the Comparable<T> interface. Google for tutorials on how to implement it; here is the official one.

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

bump..

Bumps, and that too soon after posting your thread is rude. It's weekend in almost all parts of the world with Christmas just round the corner. You sure your homework/question is more important than people's personal life? Have some patience.

Anyways, back on topic, regarding your code, a few things come to mind:

  • Are you properly overriding the equals() / hashCode() method of the BTreeNode class?
  • Rather than checking for equality, you should compare the current node with the desired node to get the desired algorithm behaviour. From wikipedia:

    We begin by examining the root node. If the tree is null, the value we are searching for does not exist in the tree. Otherwise, if the value equals the root, the search is successful. If the value is less than the root, search the left subtree. Similarly, if it is greater than the root, search the right subtree. This process is repeated until the value is found or the indicated subtree is null. If the searched value is not found before a null subtree is reached, then the item must not be present in the tree.

A sample implementation might be:

private boolean containsItem(BTreeNode<T> current, BTreeNode<T> target) {
    if(current != null) {
        if(current.compareTo(target) > 0) {
            return containsItem(current.getLeft(), target);
        } else if(current.compareTo(target) < 0) {
            return containsItem(current.getRight(), target);
        } else {
            return true;
        }
    } else {
        return false;
    }
}

Just implement the Comparable interface and you should be good to go.

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

They are different yet there is no v/s IMO, there are a few tricks to persisting enums to databases out there, namely writing out the enum name and reading it back by passing the same name to valueOf() method for that enum.

The most obvious difference is that enums are compile time constants whereas key-value pairs stored in databases are configurable. Are you absolutely sure that these mappings won't change over time? If yes, you can have an enum having fixed set of values and when it comes to persisting just persist the enum name which can be easily used to get back the original enum. If you don't have a fixed set of values, the compile time advantage offered by enums is a moot point here since you can't create compile time safe mappings on the fly.

In the end it all depends on *what* exactly you are trying to achieve. But yes, there are ways of mixing and matching enums and database mappings as long as you know what you are dealing with.

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

I've never worked on Swing/AWT but there are a couple of universal things you should know about single threaded UI toolkit (and Swing is one of them); all UI updates should be done on the rendering thread (EDT - Event dispatcher thread in case of Swing).

The problem with your code is that even though you have the motivation for running a background task, that task is very heavily involved with mutating the UI (getting the text from text area, finding highlights and highlighting them). And since you end up adding highlights in a background thread, it violates the principle of "UI updates only in the EDT. This is the reason you are getting a freeze or technically speaking a "deadlock". I'll also show you how to find out such deadlocks.

Assuming you are running JDK 6, it already comes bundled with a profiling tool called Visual VM in the bin directory. If not, just download it from the official site (google visual vm, it shouldn't be hard). Now, fire up your application and wait for it to freeze. After it has frozen/stopped responding, start Visual VM. After it has started, in the left panel of Visual VM under the "Local" category, you should see the classname of your application. Right click on it and click "Thread Dump". This should give you the thread dump of the currently executing threads. This feature also has the capability of detecting deadlocks. Just navigate to the bottom of that thread dump …

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

Yeah, based on the behaviour of the log file you posted, it seems only STDOUT is captured which means you can't use the normal e.printStackTrace() (since it redirects to STDERR).

Re-throwing the exception and handling them at a single place and using a logging library like log4j would be a good idea, but maybe leave those things when you get time. For the time being, just concentrate on capturing the stack traces and monitoring the file descriptor usage/limit on your system.

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

Read this and this; but as mentioned in my previous posts, always make sure you close *everything* (good practice, remember?) and consult your sysadmin before making any changes.

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

OK, I just looked at the source code of the Socket classes and it seems that closing any one of those three (InputStream, OutputStream, Socket) terminates the connection so that really shouldn't be a problem in your case. But the error message you posted really implies that your system has run out of file descriptors to allocate. If you run into this problem again, make sure you get the entire stack trace for it (based on my previous suggestion of using e.printStackTrace(System.out) .

Another thing you should do is find out the current open file descriptor limit on your machine and see the number of file descriptors used when your server process is running. For all we know, it might be a genuine issue of 'low defaults'. I'm no pro-system admin so you might also want to consult your system administrator for the same.

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

There are some ready to use free chat widgets out there which you can use for your site; have a look at: http://www.readwriteweb.com/archives/10_chat_widgets.php

If you are specifically looking for code which you can deploy on your servers, take a look at Holla.

Disclaimer: I haven't used any of those so do your research before using any of them.

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

I don't think saving files in a deployment directory would be a good idea. Two solutions come to mind:

  • Use a persistent storage solution like a database (e.g. SQLite) or some other NoSQL solution like Cassandra
  • If you want to go for a simpler file system based solution, read the STORAGE_PATH system property (specified by -D switch when starting the JVM) in the ServletContextListener, store it in the ServletContext and whenever you want to store a file (for e.g. in your servlet), just do:
final String storagePath =
  new File(context.getAttribute("STORAGE_PATH").toString());
final String file = new File(storagePath, 'song.mp3');
// write to file and it will be saved to the path denoted by the
// STORAGE_PATH system property
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Post the minimalistic code here which reproduces your problem instead of attaching a zip file.

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

That is not the complete stacktrace. A complete stack trace helps us know the call stack state during the time the exception was dumped on to the STDOUT/STDERR. A complete stack trace looks like:

org.omg.CORBA.MARSHAL: com.ibm.ws.pmi.server.DataDescriptor; IllegalAccessException minor code: 4942F23E completed: No
at com.ibm.rmi.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:199)
at com.ibm.rmi.iiop.CDRInputStream.read_value(CDRInputStream.java:1429)
at com.ibm.rmi.io.ValueHandlerImpl.read_Array(ValueHandlerImpl.java:625)
at com.ibm.rmi.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:273)
at com.ibm.rmi.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:189)
at com.ibm.rmi.iiop.CDRInputStream.read_value(CDRInputStream.java:1429)
at com.ibm.ejs.sm.beans._EJSRemoteStatelessPmiService_Tie._invoke(_EJSRemoteStatelessPmiService_Tie.java:613)
at com.ibm.CORBA.iiop.ExtendedServerDelegate.dispatch(ExtendedServerDelegate.java:515)
at com.ibm.CORBA.iiop.ORB.process(ORB.java:2377)
at com.ibm.CORBA.iiop.OrbWorker.run(OrbWorker.java:186)
at com.ibm.ejs.oa.pool.ThreadPool$PooledWorker.run(ThreadPool.java:104)
at com.ibm.ws.util.CachedThread.run(ThreadPool.java:137)

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

So do you think if I change it to this method will it work

OK, since it seems only STDOUT is captured by the wrapper code, a better version of your code would be:

e.printStackTrace(System.out)

Ok I will listen your advice in the last part I will close r then what else must I close. Must I close this receivedSocketConn1?

Yes, make it a rule to *always* close all resources you open. It's a good practice anyways, much better than keeping track of what gets closed automatically.

About the refactoring give me some time to absorb it. I will look through and do it and let you have a look

Take your time, one step at a time. First think of splitting all that logic in methods. Good luck.

Thank you

HTH

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

@~s.o.s~ too many colleagues are pushing for Scala, but so far I did not find it interesting

Same here; I find it too complicated and messy; maybe that's just me but there it is. If I ever think of trying out a new JVM language, it would be Clojure. :-)

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

My O.S is fedora linux. I do not know how to get the entire stack trace printed?

Just make sure that you don't catch any exceptions and gobble them (i.e. don't do anything). Either log that error using Log4J's FATAL logging level or at least do a e.printStackTrace() . Also, make sure that when you start this application on your *nix box, you don't redirect the error stream to /dev/null which might end up gobbling up all your stack traces which might have been printed.

If there was no exception stack trace, how did you know the error was 'too many open files'? Also, how are you starting the application on your *nix box? As a background process?

So normally anything I system.out.println will print in the wrapper log file. So do you think I should do the same for the stack trace?

Exception stack traces are printed out to the *error* stream instead of the standard output stream, so just make sure that your wrapper program captures both error and standard output streams (STDOUT, STDERR).

Another thing regarding the closing of the input stream I read that if w is close then automatically it take of the r too

I don't think so since nothing along those lines is written in the Javadocs for the Socket class. I'd rather play safe and close *all* open resources which were opened; this involves closing socket, input stream and output stream.

I dont know how to split the …

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

What operating system are you running on? Do you have the entire stack trace?

This error normally comes up when you end up depleting your quota of the maximum acceptable file handles which can be open at a given time which in turn happens if you don't close file/socket streams which you have opened. By having a look at your code, it seems that you never close the InputStream retrieved from the client socket (the variable ' r ') which might be what is causing these errors.

A few more things:

  1. Split your logic into methods instead of pushing the entire thing is just a single method
  2. Instead of concatenating queries, use PreparedStatement which are immune to SQL injection. For repeated execution they are faster since once a statement is "prepared" the cost of re-compilation of query is no longer there.
  3. Spawning threads on demand is expensive; use thread pools. If you are using Java >= 5, look into ExecutorService .
  4. Spawning connections on demand is also expensive; use connection pooling if your profiling suggests that the application takes a lot of time in "preparing" database resources
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I guess we are both agreeing on the same thing; using interface instead of adding a method to super-class. My point being you can use an interface for it and still get away without doing the `instanceof` checks.

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

Post the complete exception stack trace and if possible *formatted* source code.

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

You can create and edit a SQL file which contains all the initialization statements (CREATE, INSERT etc.) using a text editor like Notepad++ which supports SQL highlighting and execute the same in MySQL console using the information provided on this page. The advantage here is that whenever you need to reproduce your entire database environment on a clean MySQL install, you just execute this script and you are done! :-)

MySQL workbench looks awesome in case you are not interested in writing SQL scripts in a text editor and executing them at the console.

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

For some reason I've always shied away from instanceof checks in my code which probably implies a broken type hierarchy.

Regarding the "coding stuff in super-class"; I don't think its wrong to ask a Customer whether he/she is actually eligible for a discount since a Customer availing for a discount is not unheard of. Plus it really isn't NULL but returning a right answer in this case. We ask the question: Is a cookie cutter Customer eligible for a discount? No, cool, then return false . Is our special Member class which *ISA* Customer eligible for discount? Yes, return true .

If the situation at hand can be adjusted so that the subclass-superclass relation can be avoided (the chances of which are thin if this is a homework), we can make the Discountable interface richer such that giveDiscount() method only accepts a Discountable and can complete its entire functionality by using the methods exposed by the Discountable interface ( getDiscountRate() etc).

Of course, IMHO and YMMV. :-)

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

It seems that I must define UTF8 for each column of all tables or even recreate the DB and tables with UTF8

This doesn't actually surprise me since we are actually talking about changing the charset here.

which is very rutine task

I'm not sure about the routine part. You are a programmer, it won't be too difficult to whip up a script which does all this for you. :-)