Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!

Chad Patrick

+ Follow
since Feb 01, 2003
Chad likes ...
Netbeans IDE Oracle Java
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Chad Patrick

All of my jobs have been a real life incarnation of a Dilbert cartoon or the movie Office Space.

I'm currently working on achieving my dream of doing nothing....
12 years ago
I have a server program that has lets say 2 threads initially.. one thread is the main thread that accepts the connections (spins off connections in new client threads). the other thread(call it auxthread) is a thread thats called to do work when called by one of the clients.
How do you design it so that auxthread gets created but goes into an idle state.. so say client1 can call auxthread.dosomething(some var) and have it done in the auxthread while client 1 continutes. If another client logs in it should be able to call the same auxthread.dosomething(some var) function in the worker thread..And when they are done, auxthread goes back idle
Im sure an easy, yet unefficent way is to create a new auxthread everytime you need access to it, but id like the aux thread to stay alive and only be created once the whole program, be shareable amongst the clients (all threads can call it) and lay idle when not in use..
Anyone have any solutions.. Im sure theres probably a class or simple soltuion to this but im over thinking it..
Thanks again
Hey Nate
I appreciate the reply. In an attempt to benchmark your response with the code I already had, It insprired me to do alot more indepth looking into the recklessness of my code. It turns out that it was taking on average about 8 seconds to retrieve and perform all the appends, plus another 8-9 seconds for the jeditorpane to display. I believe that the length of one string buffer came out to be 200,000 So Im defiently gonna split the results into different pages. Maybe doing that will also cure that nasty memory leak I seemed to provoked in Jeditorpane.
Also on JeditorPane, Ive seen some posts on google referring to a memory leak with it which I think I have fallen victim to.
public class wide nonstatic variable Jeditorpane contentpane
local method called on button press
StringBuffer x = new StringBuffer();
Do a few x.appeands
After performing the above pseudocode a few times, It seems that Java never releases the memory. I can watch on Task Manager where memory usage just seems to keep growing and growing each button press. The code above is located in an ActionListener response to button press. Are there any certain precautions you should take when doing repetitive settext() calls on Jeditorpanes, or was jeditorpane never built to handle this type of repetitive display.
20 years ago
I currently have a Java application that fetches data through JDBC. My current method is to have a StringBuffer append the data it fetches and then do setText(Stringbuffer.toString()) in Jeditorpane.
r = sqlquery.executeQuery(query);
While this works, sometimes the size/amount of the html text it retrieves can range up to 200K. All the appending with string buffer can put a serious lag on performance.
Does anyone have any recommendations for possibly other Swing components that can display html or perhaps a more efficent way to display html with JEditor. I know Jeditor has a read(inputstream) which would be ideal and probably would work better, but my data source isnt an input stream.
Any one have any clever solutions to this.. or should i just give in and break down my editor into multiple "pages"
Any tips appreciated. Thanks
20 years ago
2. Use JavaScript to do the same thing, loading data to an "invisible" document, then parsing out the data and updating various elements of the HTML page.
Any chance you would know where to find examples of this? Im doing a page where im trying to get the contents of a drop down box (or are they called drop down lists?) to dynamically change (contents of the dropdown box will be loaded by database query) , and that seems like a good approach to my problem
20 years ago
I think i probably made that previous answer more complicated than it is...
I think servlets are serialized so you can save their state in the destoy() method when it unloads.. and reload it in the init().
20 years ago
I cant provide a solid answer on this, but I went to search google because I was curious about it to and on the 20th or so page of results, this link came back:
IF you search that document for "serialized", it makes reference to if more service requests are recieved than the connection pool allows, then the requests are serialized (following this particular model). I dont know if this has any relevance to your question, but its an instance where servlet serialization is used..
20 years ago
This is like the 2nd test thread you started in the last few days..
I think its working..
20 years ago
Ok heres my problem..
Im creating a webpage (servlet).. and on that page, theres 2 drop down boxes.. BoxA and BoxB.. the contents of BoxB are dependant on the selection in BoxA.. so say you select a certain date in BoxA drop down list, BoxB drop down list will contain the names of people that visited the site that day. Select a different date in BoxA, the list in BoxB will dynamically change to reflect users on the new date. in other words, When User selects a listing in boxA, the servlet will query the database and populate boxb.
I havent written any code yet, and i was planning to do this with servlets (im still a real newbie to serverside java so I was hoping to do it with servlet since it looked simpler than JSP).
I was hoping to get some pointers on or perhaps an algorithm to how this is done with servlets..
My general idea so far is:
1. user makes call to url and it displays webpage with 2 list boxes.
BoxA is initially populated with dates, BoxB is empty.
2. User selects date from BoxA, how would you get your servlet to populate
names in BoxB.
Ive seen examples that use Javascript/onchange() for drop down boxes but they populate the other drop down box with values that are already hard coded into html. Hard coding it into HTML for my project wouldnt be feasible due to the number of items that could be in BoxB. Anyone have any ideas on how to populate BoxB?
Ive already created this project as a java applet at Basically what i want to do is translate this applet into a servlet, due to the fact that 99% of the people use the old MS JVM that wont support this applet...
Again, any ideas, pointers, tips, whatever would be greatly appreciated..
20 years ago
Im a real newbie in JSP/Servlet programming and I had a question about how it interacts with JDBC database connections. (wasnt sure if i should post here or jdbc forum but i decided here cause i wanted a chance at the book
With JDBC in applets, each applet will form a connection to the database.
I read that in servlets, you put your JDBC connection code into the init() method so its loaded as soon as the servlet is loaded and im guessing it forms a connection to the database that stays active the entire time the servlet is alive? (let me know if im wrong so far) So if 2 people request the same servlet at the same time, are both of them using the same connection to the database, or does it open a new connection to the database each time the servlet is called, or perhaps, does it put requests in a queue?
Any clarification or pointers would be appreciated.
20 years ago
I had a question about the result of this code from Mughal's Java Cert book (problem 3.17 p74)
public class Logic{
public static void main( String args[]){
int i = 0;
int j = 0;
boolean t = true;
boolean r;
r= (t & 0<(i+=1));
r= (t && 0<(i+=2));
r= (t | 0<(j+=1));
r= (t || 0<(j+=2));
System.out.println(i + " "+j);
Select all valid answers.
(a) The first digit printed is 1.
(b) The first digit printed is 2.
(c) The first digit printed is 3.
(d) The second digit printed is 1.
(e) The second digit printed is 2.
(f) The second digit printed is 3.
According to the answer in the back of the book, the correct answers are (c) and (d). I understand how the shortcircuited and logical operators work, but since "i+=" and "j+=" are in parenthesis, wouldnt they be executed first in each expression/line, making the correct answers (c) and (f)... I guess im getting the left to right associativity confused with the precedence.
Can anyone clarify this?
21 years ago