• Post Reply Bookmark Topic Watch Topic
  • New Topic

refining client/server project  RSS feed

Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
I created a client/server app a while back. When the client app logs
onto the server app, the server app uses a recursive method to read in a
portion of the directory structure and write it out to stream using
zeroes and ones to indicate directories or files. The client app then
receives these zeroes and ones and recursively reconstructs a JTree
duplicating the directory structure. I was once told that this is the
best way to send this kind of data over the network in order to
reconstruct the directory structure in the JTree. However, now I'm
having my doubts.
When I originally created the project I was developing in Windows98.
I've recently upgraded to Win2000 ( a real memory hog ). I had to
upgrade my RAM from 128Mb to 320Mb. Now, when I try to run my client
app and collect the data to reconstruct the directories & files in the
JTree, the program gags and I get OutOfMemoryErrors.
I was once told that recursion is expensive on memory, so I'm wondering
if there is a better, more efficient method of reconstructing the
directories and files into a JTree than what I have been doing with the
recursive methods? I'm wondering if I'd be better off creating the
JTree object, complete with directories and files, on the server side
then simply sending the whole serialized object over the wire in one go
to the client app?
Please advise,
Ernest Friedman-Hill
author and iconoclast
Posts: 24217
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alan,
Welcome to JavaRanch!
Recursion -can- be expensive, but it's doubtful that your directory tree is so deep that this is going to be a problem -- unless there's a logical error in your program which causes it to use more memory than it should. I'm assuming that there's one recursive call for each level of the directory tree -- if there's one for each file, or something, then yes, that's going to be a problem!
If recursion is working for you, there's no compelling need to switch. But do have a look over the code and try to find unnecessary objects being created, or unnecessary copies being made.
Note that no matter how much memory is on a computer, Java won't use it unless you say so. The default heap size for Sun's recent JVMs is 64MB, and it won't grow past that; you can increase it using the -XmxNNm command-line switch, where NN is some number of megabytes; i.e.,
C:\> java -Xmx128m MyProgram
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!