| HTTP/1.1 persistent connections |
|
 |
Index ‹ java-programmer
|
- Previous
- 3
- Problem with "if - else" statement in for loopI am having problems with this section of code...
public void updateRank(){
int x = -1;
int y = -1;
String winnerMemNum = JOptionPane.showInputDialog
("Enter winner's membership number:");
int wMemNum = Integer.parseInt(winnerMemNum);
for(int i=0;i<list.size();i++){
Player temp = (Player)list.get(i);
if(temp.getMemberNumber() == wMemNum)
x = i;
else
System.out.println("Player not found");
break;
}
I want the condition in the if statement to be tested for every element
in the list before the code in the else block executes, but at the
moment it is only testing the first element. I know I need to put
brackets in, but when I did that, the whole thing stopped working! Any
ideas?
- 3
- Checbox help!!!I am trying to write a program that calculates the price when the checkboxes
are selected and the calculate button is pressed.
Now I am not sure how to code the part where you click the box and the price
of that item appears. Any suggestions?
Here is what I have now:
import java.awt.*; //Abstract Window Toolkit (AWT) for creating
//painting graphics, interfaces and images
import java.applet.*; //gives the classes for an applet to create and
//communicate in applet context
import java.awt.event.*; //gives classes and interface for different
//types of events from the AWT
import java.text.DecimalFormat; //this class formats decimal numbers
public class PetsApplet extends Applet implements ActionListener
{
//labels declared
Label welcomeLabel = new Label ("Welcome to the Pet Clinic");
Label price = new Label("The total price is $0");
Label current = new Label("The current price is $0");
Label serLabel = new Label("Select the service:");
//string text declared
String currentString = new String();
String priceString = new String();
//checkboxes identified
Checkbox officeBox = new Checkbox("Office Visits $10");
Checkbox vacBox = new Checkbox("Vaccination $25");
Checkbox xrayBox = new Checkbox("X-Rays $40");
Checkbox hosBox = new Checkbox("Hospitalization $100");
Checkbox denBox = new Checkbox("Dentistry $50");
Checkbox labBox = new Checkbox("Laboratory Work $30");
Checkbox heartBox = new Checkbox("Heartworm Prevention $35");
Checkbox boardBox = new Checkbox("Boarding $5");
Checkbox preBox = new Checkbox("Prescription $55");
Button calcButton = new Button ("Calculate");
Label outputLabel = new Label("Click the calculate button for total price");
//price variables of the services declared along with the totalPrice
int totalPrice = 0;
int officeBoxPrice = 10, vacBoxPrice = 25, xrayBoxPrice = 40, hosBoxPrice =
100;
int denBoxPrice = 50, labBoxPrice = 30, heartBoxPrice = 35, boardBoxPrice =
5, preBoxPrice = 55;
public void init()
{
//adds all the components to the applet interface
setBackground (Color.blue);
add(welcomeLabel);
add(serLabel);
add(officeBox);
add(vacBox);
add(xrayBox);
add(hosBox);
add(denBox);
add(labBox);
add(heartBox);
add(boardBox);
add(preBox);
add(current);
add(calcButton);
calcButton.addActionListener(this);
add(outputLabel);
add(price);
}
public void actionPerformed(ActionEvent e)
{
//the current price statement is identified
if (officeBox.getState())
currentString = ("The current price is $"+ Integer.toString
(officeBoxPrice));
if (vacBox.getState())
currentString = ("The current price is $"+ Integer.toString (vacBoxPrice))
;
if (xrayBox.getState())
currentString = ("The current price is $"+ Integer.toString (xrayBoxPrice))
;
if (hosBox.getState())
currentString = ("The current price is $"+ Integer.toString (hosBoxPrice))
;
if (denBox.getState())
currentString = ("The current price is $"+ Integer.toString (denBoxPrice))
;
if (labBox.getState())
currentString = ("The current price is $"+ Integer.toString (labBoxPrice))
;
if (heartBox.getState())
currentString = ("The current price is $"+ Integer.toString (heartBoxPrice)
);
if (boardBox.getState())
currentString = ("The current price is $"+ Integer.toString (boardBoxPrice)
);
if (preBox.getState())
currentString = ("The current price is $"+ Integer.toString (preBoxPrice))
;
//the text is set equal to currentString
current.setText (currentString);
//total price is calculated
totalPrice = 0;
if (officeBox.getState())
totalPrice += officeBoxPrice;
if (vacBox.getState())
totalPrice += vacBoxPrice;
if (xrayBox.getState())
totalPrice += xrayBoxPrice;
if (hosBox.getState())
totalPrice += hosBoxPrice;
if (denBox.getState())
totalPrice += denBoxPrice;
if (labBox.getState())
totalPrice += labBoxPrice;
if (heartBox.getState())
totalPrice += heartBoxPrice;
if (boardBox.getState())
totalPrice += boardBoxPrice;
if (preBox.getState())
totalPrice += preBoxPrice;
//output statement for total price is identified
priceString = ("The total price is $" + Integer.toString (totalPrice));
price.setText (priceString);
//statements to clear the fields after the calculate button is clicked
officeBox.setState(false);
vacBox.setState(false);
xrayBox.setState(false);
hosBox.setState(false);
denBox.setState(false);
labBox.setState(false);
heartBox.setState(false);
boardBox.setState(false);
preBox.setState(false);
}
}
- 5
- Can start() method access applet parameters?I have a signed applet that needs to read in data passed from HTML
page
via PARAM elements defined in EMBED tag. Since I cannot launch a
method
directly via JavaScript (bug), I thought I'd try to see if I could get
the
code to run as needed via the start() method by reloading the page.
But my
applet is not recognizing the parameter values being passed in (when
output
for debugging, they show up as null). Can parameters be passed like
this to
the start() method??
Test HTML page:
<html>
<head><title>
Test a Signed Applet
</title></head>
<body>
<EMBED type="application/x-java-applet;jpi-version=1.4.2"
name="Launch" code="LaunchHSDXPlugIn.class"
archive="LaunchHSDXPlugIn.jar" WIDTH=120 HEIGHT=75
<PARAM NAME="ImageFile"
VALUE="\\ain-www06.devsrv\output\mapfile.jpg">
<PARAM NAME="VBCodeLocation"
VALUE="\\ain-www06.devsrv\RivCopy\CopytoClipboard.exe">
</EMBED>
<br><br>
<img name="copy" src="copy.png" onMouseDown="location.reload(true);">
</body>
</html>
Test JAVA code:
import java.applet.*;
import java.io.*;
public class LaunchHSDXPlugIn extends Applet
{
public void start()
{
System.out.println("\n** In start method.\n");
try
{
String getval = null;
getval = getParameter("ImageFile");
System.out.println("the imagefile is " + getval);
Runtime.getRuntime().exec("w:\\hyperionics\\hypersnap\\hsdx.exe -
fixed_title " + getval);
Thread.sleep(2500);
getval = getParameter("VBCodeLocation");
System.out.println("the vbcodelocation is " + getval);
Runtime.getRuntime().exec(getval);
}
catch (SecurityException e1)
{
System.out.println("\n** An access control error occurred
attempting to run LaunchHSDXPlugIn applet.\n");
e1.printStackTrace();
}
catch (IOException e2)
{
System.out.println("\n** Error attempting to execute HyperSnap or
copy to clipboard.\n");
e2.printStackTrace();
}
catch (Exception e3)
{
System.out.println("\n** An error occurred attempting to run
LaunchHSDXPlugIn applet.\n");
e3.printStackTrace();
}
}
}
- 7
- java parserHello,
I am new to programming and I need to create a parser for an
application using java. I am using J++ to complete this task. Any
help or advice would be greatly appreciated.
Also, Can anyone assist me in creating a simple progress bar?
Thanks,
Brad
- 8
- Accessing the associated dataModel when a particular frame is selectedI have JDesktop containing one or more JInternalFrames. Each of these
frames contains a JScrollPane which in turn contains a JTable, each
with its own tableModel. I wish to add a row to the table in the
currently selected frame. How do I recover the tableModel to do this?
I can do it if I only have a single table using:
table.getModel().addRow(item);
but it would be easier for my end users if they could have multiple
tables open. The tables all have the same structure but have differing
numbers of rows. I also may need to edit existing items in the tables.
In line with the MVC architecture of Swing, it appears as if I am
trying to get to the model through the view rather than keeping the
model separate. This implies that I should keep a list (collection?)
of each model as I create it in my application. The difficulty then
becomes associating the currently selected view with the appropriate
model so that the editing is done in the appropriate table.
Any ideas or suggestions?
Oh, and a happy new year to everyone :-)
Bob
- 8
- JTabbedPane doesn't follow Sun's UI standard?
I'm using the JTabbedPane control.
While looking for a way to get rid of the line between the tabs and the
selected frame, I noticed that the Sun guidelines show that there shouldn't
be one there in the first place:
http://java.sun.com/products/jlf/ed2/book/HIG.Windows3.html#38176
Is this maybe a result of using the system L&F on MS windows?
Is there any way of changing this?
-Bella
- 9
- Problem communicating with socket applicationI am experiencing problems when trying to communicate with a TCP socket
based application that does not always append a <CR> at the end of the data
and so cannot use readLine on a BufferedInputStream.
I have tried using a simple read in to a char array but have found that
where the application has sent 4 records using 4 separate socket writes, my
read operation has resulted in them all being read in to one array and I
have no means of determining where one record ends and the next begins,
unless there are <CR> appended to each record, which as I stated is not
always the case :(
Using a normal unix socket read operation in C++ I would not have this
problem as each read operation would result in one record.
How can I get java sockets to operate in a similar manner as unix socket
reads so that one record is obtained in each read operation, regardless of
whether it is appended with a <CR> or not?
TIA,
Pep.
- 9
- Java clock offsettable by minutes?I'm trying to find a Java clock applet that will allow me to offset the
minutes. Ideally, something attractive, customizable, TZ-sensitive *AND*
with a minutes offset.
I've searched pretty thoroughly, but that last requirement doesn't seem to
exist in the online archives. (Note that I mean a real minutes offset, not
just a 0030 TZ offset - i.e., make the clock run exactly 10 minutes slow or
15 minutes fast.)
Oh, and something outta the box... I'm, uh, not a Java programmer. :P
Ad(thanks)vance.
--
|=- James Gifford = FIX SPAMTRAP TO REPLY -=|
|=- So... your philosophy fits in a sig, does it? -=|
- 9
- Using pictures from the jar?
I create the jar with my classes, pictures and some txt files. The
application is starting just fine if picture folder is out of the jar.
If the folder picture is in the jar I don't see the pictures on my buttons
and everywhere.
How to solve that problem?
- 10
- Available memory and limit on thread creationJoseph Dionne wrote:
<snip>
>> Of course if you only had a J2EE server...
>> Seriously, this is the sort of situation where you could justify
>> the complexity and expense. Stateless or even stateful session
>> EJBs would fit the bill. Let the container manage the details.
>> Why re-invent the wheel?
>
> Because I have a frugal customer who is already not terribly excited
> about paying my bill? The real world sucks!
Read Roedy's reply carefully. He was able to succinctly describe the
limitations of the HTTP protocol, namely that it's stateless. What I
would suggest you consider is a hybrid of available technologies.
Given what you've described to-date, I would lean towards a JMS
solution. This would provide "loose coupling" and incorporates some
of Roedy's suggestions in terms of queueing requests/responses.
Insofar as J2EE servers, have you had a look at JBoss? While I
wouldn't recommend it for commercial, mission-critical applications,
it can serve as a powerful development platform when linked with the
Eclipse IDE. It might be enough to demonstrate to your client that
there IS a better way.
I'm just throwing out suggestions as what you're describing is quite
complex and would involve a major investment in time for development.
That will translate to $$, no matter how much or little you charge
per hour.
- 11
- Progress bar to show the progress of a taskIn my application one click on the start button will fire one specific
task which includes some numerical computation routines and data
visualization routines.
Want to use progress bar to show the progress of the task execution,
even after reading sun's java swing tutorials still not clear how to
set the maximum length of the progress bar and update the progress
status.
Really appreciate your time and kind help!
Thanks a lot.
- 11
- Newbies doubts on JavaHi All:
I am mainly a C++ programmer. Recently, I need to do cross platform
development work and Java came across my mind. My worries are as
follows:
1. Is Java suitable as a language to develop software application in
an operational environment? My company needs to run application 24hrs
a day and 7 days a week (ie. non stop). I have heard that Java is
slower than C++ and Java has a larger memory footprint as compared to
C++. Are these true?
2. I have came across wonderfully written Java applications that works
smoothly. May I know is there any tips or tricks whereby one can
follow to streamline a Java program, such as conforming to certain
architecture or design principles etc.
Thank you for your time in answering these naive questions.
- 14
- Java maybe, some help with something puzzlingHi all,
I was given this quiz as it were. I'm asked certain questions about
two snippets of code. The questions do not indicate the programming
language. I'm mainly familiar with java methods but don't know if other
languages would also use "methods." I'm also a bit confused because an
Array, which is indicated in the code below, should have the square brackets
[] and yet this code snippet is lacking that. Any advice on what I might
want to look at to understand this code further would be
greatly appreciated. Sorry if I seem ignorant here.
1. Consider the following method:
private int wrongCode(Integer num){
if (num > 6){
return num - 5;
} else {
return num.parseInt();
}
}
What are the errors?
2. Consider the following methods:
public int run() {
List group1 = new ArrayList();
for (int i=0;i<3;i++) {
group1.add(i);
}
List group2 = this.makeNewList(group1);
return group2.size() - group1.size();
}
private List makeNewList(List list) {
List other = list;
other.remove(other.size() - 1);
return other;
}
What value is returned from the method run() after it is called?
Thanks,
bruce
- 14
- Event-Handling: Using one single class for different events?
Hi!
I am rather new to Java, so please, don't blame me for this question.
What I want is to seperate the GUI- from the Application code. Hence,
I have created three classes:
1. a Main class
2. a MainFrameCommand class, which parses the events
3. a MainFrameGUI class, that creates and paints the gui
(for a trivial example see end of this post)
Now, my question is this: Is it correct, to put all the various events
into one single command class (i.e, Focus-, Key-, Mouse-, and Windows-
Events) and then register the various event-listeners using this
single class?
It works perfectly, however, I wonder if this is a legal way to do so,
or is it necessary to create a seperate class for every different
event-listener-type?
Example:
------------------------------------------------------------
1. Main Class
------------------------------------------------------------
class Main {
public static void main(final String[] args) {
MainFrameCommand cmd = new MainFrameCommand();
MainFrameGUI gui = new MainFrameGUI(cmd);
}
}
------------------------------------------------------------
2. MainFrameCommand Class
------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
class MainFrameCommand
implements KeyListener, MouseMotionListener, WindowListener {
/* Key Listener */
public void keyPressed(KeyEvent event) {}
public void keyReleased(KeyEvent event) {}
public void keyTyped(KeyEvent event) {}
/* MouseMotion Listener */
public void mouseMoved(MouseEvent event) {}
public void mouseDragged(MouseEvent event) {}
/* WindowListener */
public void windowClosed(WindowEvent event) {}
public void windowOpened(WindowEvent event) {}
public void windowClosing(WindowEvent event) {}
public void windowActivated(WindowEvent event) {}
public void windowDeactivated(WindowEvent event) {}
public void windowIconified(WindowEvent event) {}
public void windowDeiconified(WindowEvent event) {}
}
------------------------------------------------------------
3. MainFrameGUI Class
------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
class MainFrameGUI extends Frame {
public MainFrameGUI(MainFrameCommand cmd) {
super("Window");
setSize(300, 300);
setVisible(true);
/* !!!!!!!!!!!!!!!!!!!!!!! HERE'S THE CRUCIAL QUESTION
!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!! Is it legal to add register all these
!!!!!!!!!!!!!!!!!!!!!!! event listeners using the same object?!?
*/
addKeyListener(cmd);
addWindowListener(cmd);
addMouseMotionListener(cmd);
}
public void paint(Graphics g) {}
}
- 15
- Newbie question on stopping an applicationI have a simple console application that prompts the user to enter two
numbers and then the program multiplies these two numbers and spits out
the product. No problem so far. The difficulty I'm having is that if
someone enters a negative number, I want the program to reply something
like "Does not accept negative numbers!" then stop. I tried using
"break;" but it generated an error message and said that I was using it
"outside the loop" or something like that. I would be grateful if
someone could give me a clue on what I might use for this. Thank you
very much. My code is below.
public class Kilowatt
{
private double costKiloWattHours; //example 8.42 which means cents
private double hoursUsedPerYear; //example 653
private double annualCost;
public void setCost(double cost)
{
if (cost <= 0)
{
//I want the program to say "You can't enter a negative number."
//Then the program should stop execution.
}
else
{
costKiloWattHours = cost / 100;
}
}
public void setHours(double hours)
{
hoursUsedPerYear = hours;
}
public double getAnnualCost()
{
annualCost = costKiloWattHours * hoursUsedPerYear;
return annualCost;
}
}
import java.util.Scanner;
class Kilowatt_Test
{
public static void main(String[] args)
{
double myCost;
double myHours;
Scanner myScanner = new Scanner(System.in);
System.out.print("What's the cost per kilowatt hour? ");
myCost = myScanner.nextDouble();
Kilowatt myKilowatt = new Kilowatt();
myKilowatt.setCost(myCost);
System.out.print("How many kilowatt-hours are used per year? ");
myHours = myScanner.nextDouble();
myKilowatt.setHours(myHours);
System.out.println("The annual cost is: " +
myKilowatt.getAnnualCost());
}
}
|
| Author |
Message |
Alex Hunsley

|
Posted: 2004-2-13 20:22:00 |
Top |
java-programmer, HTTP/1.1 persistent connections
(Sorry, can't post any complete example code for this at the minute
which is really annoying, I know.)
AFAIK, when java is using HttpURLConnections with HTTP/1.1 (as it is in
my situation), repeated connections to the same host will re-use an
existing established HTTP connection. This appears to be the case for
normal HTTP URLS - I'm doing something like this:
URL url = new URL("http://guff.here.etc/");
HttpURLConnection urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
osw = new OutputStreamWriter(httpURLConn.getOutputStream());
bw = new BufferedWriter(osw);
.. etc..
while I'm do this repeatedly in java, I can see by running 'netstat -a'
(windows 2000 machine) that there is indeed only one connection being used:
$ netstat -a | grep 199
TCP localhost:2282 remote.host.name:80 ESTABLISHED
$
..despite the fact that I'm doing many GETs from this URL. this is
desirable, only having one connection, as it uses less resources
(connector threads) in tomcat.
Now, if I have an https (SSL) link: (connecting to tomcat running an SSL
connector on port 19929)
URL url = new URL("https://guff.here.etc:19929/");
HttpURLConnection urlConn = url.openConnection();
// call setDefaultSSLSocketFactory(...) here...
// set the HostVerifier here...
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
osw = new OutputStreamWriter(httpURLConn.getOutputStream());
bw = new BufferedWriter(osw);
...etc.
... it works, but each GET is spawning a new connection, and a new
connector thread on tomcat.
e.g. netstat gives me the following:
$ netstat -a | grep 199
TCP localhost:2049 remote.host.name:19929 ESTABLISHED
TCP localhost:2051 remote.host.name:19929 ESTABLISHED
TCP localhost:knetd remote.host.name:19929 ESTABLISHED
TCP localhost:2055 remote.host.name:19929 ESTABLISHED
TCP localhost:2057 remote.host.name:19929 ESTABLISHED
TCP localhost:2059 remote.host.name:19929 ESTABLISHED
TCP localhost:2061 remote.host.name:19929 ESTABLISHED
..[snipped many more lines like this!]....
Because the link isn't persistent like HTTP, tomcat soon runs out of
threads as it is using a thread for each connection, and I start getting
refused requests as a result of this.
I searched around in the usual places, and found someone with the same
problem, and it turned out the cause in his case was that he wasn't
calling close() on his OutputStreamWriter that was being used to feed
his query into his GET. I am calling close() here, however, so that's
not the problem...
Just on the offchance that someone is familiar with this problem!
thanks,
alex
|
| |
|
| |
 |
Ryan Stewart

|
Posted: 2004-2-13 21:06:00 |
Top |
java-programmer >> HTTP/1.1 persistent connections
"Alex Hunsley" <email***@***.com> wrote in message
news:email***@***.com...
>
> (Sorry, can't post any complete example code for this at the minute
> which is really annoying, I know.)
>
>
> AFAIK, when java is using HttpURLConnections with HTTP/1.1 (as it is in
> my situation), repeated connections to the same host will re-use an
> existing established HTTP connection. This appears to be the case for
> normal HTTP URLS - I'm doing something like this:
>
> URL url = new URL("http://guff.here.etc/");
> HttpURLConnection urlConn = url.openConnection();
>
> urlConn.setDoInput(true);
> urlConn.setDoOutput(true);
> osw = new OutputStreamWriter(httpURLConn.getOutputStream());
> bw = new BufferedWriter(osw);
>
> .. etc..
>
>
>
> while I'm do this repeatedly in java, I can see by running 'netstat -a'
> (windows 2000 machine) that there is indeed only one connection being
used:
>
> $ netstat -a | grep 199
> TCP localhost:2282 remote.host.name:80 ESTABLISHED
>
> $
>
> ..despite the fact that I'm doing many GETs from this URL. this is
> desirable, only having one connection, as it uses less resources
> (connector threads) in tomcat.
>
>
> Now, if I have an https (SSL) link: (connecting to tomcat running an SSL
> connector on port 19929)
>
> URL url = new URL("https://guff.here.etc:19929/");
> HttpURLConnection urlConn = url.openConnection();
>
> // call setDefaultSSLSocketFactory(...) here...
> // set the HostVerifier here...
>
> urlConn.setDoInput(true);
> urlConn.setDoOutput(true);
> osw = new OutputStreamWriter(httpURLConn.getOutputStream());
> bw = new BufferedWriter(osw);
> ...etc.
>
> ... it works, but each GET is spawning a new connection, and a new
> connector thread on tomcat.
> e.g. netstat gives me the following:
>
> $ netstat -a | grep 199
> TCP localhost:2049 remote.host.name:19929 ESTABLISHED
> TCP localhost:2051 remote.host.name:19929 ESTABLISHED
> TCP localhost:knetd remote.host.name:19929 ESTABLISHED
> TCP localhost:2055 remote.host.name:19929 ESTABLISHED
> TCP localhost:2057 remote.host.name:19929 ESTABLISHED
> TCP localhost:2059 remote.host.name:19929 ESTABLISHED
> TCP localhost:2061 remote.host.name:19929 ESTABLISHED
> ..[snipped many more lines like this!]....
>
> Because the link isn't persistent like HTTP, tomcat soon runs out of
> threads as it is using a thread for each connection, and I start getting
> refused requests as a result of this.
>
> I searched around in the usual places, and found someone with the same
> problem, and it turned out the cause in his case was that he wasn't
> calling close() on his OutputStreamWriter that was being used to feed
> his query into his GET. I am calling close() here, however, so that's
> not the problem...
>
> Just on the offchance that someone is familiar with this problem!
>
> thanks,
> alex
In my limited experience with SSL, the port hopping is normal. Isn't it part
of the protocol, supposed to enhance security by changing connections
frequently?
|
| |
|
| |
 |
Alex Hunsley

|
Posted: 2004-2-13 22:15:00 |
Top |
java-programmer >> HTTP/1.1 persistent connections
Ryan Stewart wrote:
> "Alex Hunsley" <email***@***.com> wrote in message
> news:email***@***.com...
>
>>(Sorry, can't post any complete example code for this at the minute
>>which is really annoying, I know.)
>>
>>
>>AFAIK, when java is using HttpURLConnections with HTTP/1.1 (as it is in
>>my situation), repeated connections to the same host will re-use an
>>existing established HTTP connection. This appears to be the case for
>>normal HTTP URLS - I'm doing something like this:
>>
>> URL url = new URL("http://guff.here.etc/");
>> HttpURLConnection urlConn = url.openConnection();
>>
>> urlConn.setDoInput(true);
>> urlConn.setDoOutput(true);
>> osw = new OutputStreamWriter(httpURLConn.getOutputStream());
>> bw = new BufferedWriter(osw);
>>
>>.. etc..
>>
>>
>>
>>while I'm do this repeatedly in java, I can see by running 'netstat -a'
>>(windows 2000 machine) that there is indeed only one connection being
>
> used:
>
>>$ netstat -a | grep 199
>> TCP localhost:2282 remote.host.name:80 ESTABLISHED
>>
>>$
>>
>>..despite the fact that I'm doing many GETs from this URL. this is
>>desirable, only having one connection, as it uses less resources
>>(connector threads) in tomcat.
>>
>>
>>Now, if I have an https (SSL) link: (connecting to tomcat running an SSL
>>connector on port 19929)
>>
>> URL url = new URL("https://guff.here.etc:19929/");
>> HttpURLConnection urlConn = url.openConnection();
>>
>> // call setDefaultSSLSocketFactory(...) here...
>>// set the HostVerifier here...
>>
>> urlConn.setDoInput(true);
>> urlConn.setDoOutput(true);
>> osw = new OutputStreamWriter(httpURLConn.getOutputStream());
>> bw = new BufferedWriter(osw);
>>...etc.
>>
>>... it works, but each GET is spawning a new connection, and a new
>>connector thread on tomcat.
>>e.g. netstat gives me the following:
>>
>>$ netstat -a | grep 199
>> TCP localhost:2049 remote.host.name:19929 ESTABLISHED
>> TCP localhost:2051 remote.host.name:19929 ESTABLISHED
>> TCP localhost:knetd remote.host.name:19929 ESTABLISHED
>> TCP localhost:2055 remote.host.name:19929 ESTABLISHED
>> TCP localhost:2057 remote.host.name:19929 ESTABLISHED
>> TCP localhost:2059 remote.host.name:19929 ESTABLISHED
>> TCP localhost:2061 remote.host.name:19929 ESTABLISHED
>>..[snipped many more lines like this!]....
>>
>>Because the link isn't persistent like HTTP, tomcat soon runs out of
>>threads as it is using a thread for each connection, and I start getting
>>refused requests as a result of this.
>>
>>I searched around in the usual places, and found someone with the same
>>problem, and it turned out the cause in his case was that he wasn't
>>calling close() on his OutputStreamWriter that was being used to feed
>>his query into his GET. I am calling close() here, however, so that's
>>not the problem...
>>
>>Just on the offchance that someone is familiar with this problem!
>>
>>thanks,
>>alex
>
>
> In my limited experience with SSL, the port hopping is normal. Isn't it part
> of the protocol, supposed to enhance security by changing connections
> frequently?
I don't think so... and it's majorly taking up server resources for
tomcat as well, as each different connection uses up a different thread.
This all suggests that I'm not shutting down my connection properly at
my end....
Well, I took out the guts of the code to make a self-contained runnable
example, it's put up here:
http://www.lardus.myby.co.uk/SSLthrasher.html
(it's preformatted text with no line wrap, so watch out!)
The bummer is that when I run *this*, netstat -a shows only one
connection being made, which is what I want! <g> bums.. now have to
work out why this code does things correctly, whereas the code it's
yanked out from (and based on!) doesn't...
This code may be of help to others wanting to do SSL queries as well.
thanks,
alex
|
| |
|
| |
 |
Chris Smith

|
Posted: 2004-2-13 22:49:00 |
Top |
java-programmer >> HTTP/1.1 persistent connections
Alex Hunsley wrote:
> AFAIK, when java is using HttpURLConnections with HTTP/1.1 (as it is in
> my situation), repeated connections to the same host will re-use an
> existing established HTTP connection. This appears to be the case for
> normal HTTP URLS [...]
> Now, if I have an https (SSL) link: (connecting to tomcat running an SSL
> connector on port 19929) [...]
> ... it works, but each GET is spawning a new connection, and a new
> connector thread on tomcat.
Yep. IME, Java's implementation of HttpsURLConnection doesn't do keep-
alive connections. You could switch to a different HTTP access library
(for example, Jakarta Commons HttpClient) or try to provide a better
implementation of HttpsURLConnection through the pluggable URLConnection
architecture...
Or you could realize that there's something fishy going on in your
client. If you want to establish a connection and then close it, then
establish another connection, and so forth, then go ahead and do that.
If you're accumulating connections over time, it looks like you aren't
properly closing prior connections.
> I searched around in the usual places, and found someone with the same
> problem, and it turned out the cause in his case was that he wasn't
> calling close() on his OutputStreamWriter that was being used to feed
> his query into his GET. I am calling close() here, however, so that's
> not the problem...
Well, if that's really the case, then you do need to post a reproducible
test case.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
|
| |
|
| |
 |
Alex Hunsley

|
Posted: 2004-2-13 23:02:00 |
Top |
java-programmer >> HTTP/1.1 persistent connections
Alex Hunsley wrote:
> Ryan Stewart wrote:
>
>> "Alex Hunsley" <email***@***.com> wrote in message
>> news:email***@***.com...
>>
>>> (Sorry, can't post any complete example code for this at the minute
>>> which is really annoying, I know.)
>>>
>>>
>>> AFAIK, when java is using HttpURLConnections with HTTP/1.1 (as it is in
>>> my situation), repeated connections to the same host will re-use an
>>> existing established HTTP connection. This appears to be the case for
>>> normal HTTP URLS - I'm doing something like this:
>>>
>>> URL url = new URL("http://guff.here.etc/");
>>> HttpURLConnection urlConn = url.openConnection();
>>>
>>> urlConn.setDoInput(true);
>>> urlConn.setDoOutput(true);
>>> osw = new OutputStreamWriter(httpURLConn.getOutputStream());
>>> bw = new BufferedWriter(osw);
>>>
>>> .. etc..
>>>
>>>
>>>
>>> while I'm do this repeatedly in java, I can see by running 'netstat -a'
>>> (windows 2000 machine) that there is indeed only one connection being
>>
>>
>> used:
>>
>>> $ netstat -a | grep 199
>>> TCP localhost:2282 remote.host.name:80 ESTABLISHED
>>>
>>> $
>>>
>>> ..despite the fact that I'm doing many GETs from this URL. this is
>>> desirable, only having one connection, as it uses less resources
>>> (connector threads) in tomcat.
>>>
>>>
>>> Now, if I have an https (SSL) link: (connecting to tomcat running an SSL
>>> connector on port 19929)
>>>
>>> URL url = new URL("https://guff.here.etc:19929/");
>>> HttpURLConnection urlConn = url.openConnection();
>>>
>>> // call setDefaultSSLSocketFactory(...) here...
>>> // set the HostVerifier here...
>>>
>>> urlConn.setDoInput(true);
>>> urlConn.setDoOutput(true);
>>> osw = new OutputStreamWriter(httpURLConn.getOutputStream());
>>> bw = new BufferedWriter(osw);
>>> ...etc.
>>>
>>> ... it works, but each GET is spawning a new connection, and a new
>>> connector thread on tomcat.
>>> e.g. netstat gives me the following:
>>>
>>> $ netstat -a | grep 199
>>> TCP localhost:2049 remote.host.name:19929 ESTABLISHED
>>> TCP localhost:2051 remote.host.name:19929 ESTABLISHED
>>> TCP localhost:knetd remote.host.name:19929 ESTABLISHED
>>> TCP localhost:2055 remote.host.name:19929 ESTABLISHED
>>> TCP localhost:2057 remote.host.name:19929 ESTABLISHED
>>> TCP localhost:2059 remote.host.name:19929 ESTABLISHED
>>> TCP localhost:2061 remote.host.name:19929 ESTABLISHED
>>> ..[snipped many more lines like this!]....
>>>
>>> Because the link isn't persistent like HTTP, tomcat soon runs out of
>>> threads as it is using a thread for each connection, and I start getting
>>> refused requests as a result of this.
>>>
>>> I searched around in the usual places, and found someone with the same
>>> problem, and it turned out the cause in his case was that he wasn't
>>> calling close() on his OutputStreamWriter that was being used to feed
>>> his query into his GET. I am calling close() here, however, so that's
>>> not the problem...
>>>
>>> Just on the offchance that someone is familiar with this problem!
>>>
>>> thanks,
>>> alex
>>
>>
>>
>> In my limited experience with SSL, the port hopping is normal. Isn't
>> it part
>> of the protocol, supposed to enhance security by changing connections
>> frequently?
>
>
> I don't think so... and it's majorly taking up server resources for
> tomcat as well, as each different connection uses up a different thread.
Aha, I've just noticed that my test program *does* actually open a new
SSL connection on a different (increasing) port... my problem , when it
occurs, is that old connections just aren't closing.
The detective work continues....
alex
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- ATL - Sr. Java Developers @ www.StatCom.com - Hospital Patient Flow Logistics SoftwareSr. Java Technical Lead
Do you enjoy working with the best of the best software developers? How
about working on one of the hospital industries most important
technological innovations?
SEND RESUME & COVER LETTER TO : email***@***.com
OR call 770.643.5640
StatCom http://www.statcom.com - a division of Jackson Healthcare
Solutions - , located in Alpharetta, GA is seeking a senior Java
Software development professional with an in depth knowledge of complex
application development using the latest tools and techniques Java
offers.
StatCom is a leading developer of real-time, web-based healthcare
software. We have an excellent opportunity for a Sr. Java
Developer/Technical Lead who is a self starter who thrives in an
entrepreneurial and creative development environment.
Required Skills
?Sr. Java Developer with a minimum of 5+ years of Java development
experience.
?Candidates should have excellent technical expertise with Java along
with excellent written and verbal communication skills.
?You must be comfortable in a dynamic, fast paced, high tech,
entrepreneurial environment.
?You will do hands on development and technical mentoring.
?You must be comfortable working with loose specifications.
?Healthcare industry experience is a plus.
?Complex distributed application development experience is desirable.
________________________________________________________
Technical Environment:
Operating systems:
?Windows, UNIX, Linux
Programming languages:
?Java, JSP, J2EE, Servlets, HTML, Javascript, XML; Actionscript
Development tools:
?Oracle, SQL
JOB DESCRIPTION:
1. The ideal candidate will be responsible for designing and writing
production code for the Statcom applications and is expected to be able
to analyze requirements and take responsibility for implementing the
features to completion.
2. Our working environment encourages discussion to figure out the
right way to get the job done, but also how to move quickly when
necessary.
3. Will be working on highly multi-threaded server applications and MVC
based GUIs.
4. Will get opportunities to upgrade expertise and skills through
mentoring and training.
5. Will learn the latest software development practices, methods
conventions and standards as executed within the company.
6. Our use of technologies include our own real-time messaging system,
rules engine, dynamic display and forms technology written in server
side java with the presentation layer using flash and jsp.
7. This position is based in Atlanta.
About StatCom http://www.statcom.com:
Because StatCom is Web-based, only Internet Explorer and Macromedia
Flash plug-ins are required on the client side. StatCom monitors data
in real-time from information systems such as HIS, scheduling, asset
tracking and ADT. It also acquires event, location and date/time data
from an array of input devices:
StatCom Web displays, located on
?Plasma displays
?Workstations
?Tablet PCs
StatCom WIBUT
StatCom TIP
Barcode scanners and RFID
Telephone/IVR
PDAs
Other devices customized to the client's specifications
StatCom takes the acquired data and uses its rules-based workflow
engine and message router to drive two actions critical to patient
flow: instant communication and automated workflow. In other words, it
determines to whom or where to send the data (instant communication),
as well as the correct message to facilitate the next action (automated
workflow).
RECENT NEWS ABOUT US
Jackson Healthcare Solutions Hits $100 Million in Revenue
Some of the milestones JHS has achieved in the past year are:
?September 2005 JHS ranked in the Top 10 A+Employers and best places
to work , according to the Atlanta Business Chronicle.
?April 2005 JHS is one of the Top 25 fastest growth Atlanta based
companies in 2005, according to the Atlanta Business Chronicle.
?December 2004 JHS is one of the Top 10 privately held Atlanta
Healthcare Companies in 2005, according to INC 500 magazine.
?From 2000-2005, Jackson Healthcare Solutions revenues have
skyrocketed from $20,000,000 to $137,000,000.
?May 2005 - JHS unveiled our technology vision center - HI-TECH
Virtual hospital simulation suite
Benefits
We provide competitive compensation and an attractive benefits package,
offering:
Medical, dental and vision care insurance
Health Care and Dependent Care Personal Spending Accounts
Life Insurance
Short and Long-Term Disability Insurance
401(K) plan with company match
Paid Vacation
Paid Holidays
- 2
- Eclipse 3.0 + Native JDK 1.4Thanks everyone for the help building jdk 1.4. I've got Eclipse 3.0
built but it's throwing this error on startup then crashes:
!SESSION Aug 07, 2004 17:32:49.61
----------------------------------------------
eclipse.buildId=200406251208
java.version=1.4.2-p6
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=freebsd, ARCH=x86, WS=gtk, NL=en
!ENTRY org.eclipse.osgi Aug 07, 2004 17:32:49.63
!MESSAGE Startup error
!STACK 1
java.lang.IllegalStateException: Bundle
initial@reference:file:/usr/local/eclipse/plugins/org.eclipse.core.runtime_3.0.0/
was not resolved.
at
org.eclipse.core.runtime.adaptor.EclipseStarter.startBundles(EclipseStarter.java:824)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.loadBasicBundles(EclipseStarter.java:439)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:222)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:127)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.eclipse.core.launcher.Main.basicRun(Main.java:183)
at org.eclipse.core.launcher.Main.run(Main.java:644)
at org.eclipse.core.launcher.Main.main(Main.java:628)
!ENTRY org.eclipse.osgi Aug 07, 2004 17:32:49.80
!MESSAGE Bundle
initial@reference:file:/usr/local/eclipse/plugins/org.eclipse.core.runtime_3.0.0/
[1] was not resolved.
!ENTRY org.eclipse.osgi Aug 07, 2004 17:32:49.82
!MESSAGE Bundle
initial@reference:file:/usr/local/eclipse/plugins/org.eclipse.update.configurator_3.0.0/
[2] was not resolved.
.
.
.
.
.
And it goes on like that for quite some time. Has anyone else run into
this one? I can't find anything in the list archive.
Thanks
- Fred McCann
_______________________________________________
email***@***.com mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-java
To unsubscribe, send any mail to "email***@***.com"
- 3
- RenderingHints doesnt seem to disable the Java2D dithering, how can this be stopped?!I have seen this question being posted before, and some workarounds
suggested, however it always seemed to be in an applet context and as
such the worarounds were not usable to me.
Using the code pasted below, I draw a directcolormodel image on a
indexcolormodel image, with a ready-calculated indexcolormodel
provided.
But the images have problems and the quality is not good because solid
filled areas are dithered into half tones when half tones are available
in the palette in the indexcolormodel provided. I try to stop java from
changing the colors of the pixels in my image by setting the dither
disble rendering hint but this has no effect.
Is this a bug or do I have to take and special steps to make the
rendring hint count ?
BufferedImage newImage = new
BufferedImage(image.getWidth(),image.getHeight(),BufferedImage.TYPE_BYTE_INDEXED,(IndexColorModel)cm);
gfx.setRenderingHint(RenderingHints.KEY_DITHERING,RenderingHints.VALUE_DITHER_DISABLE);
gfx.drawImage(image,0,0,null);
gfx.dispose();
- 4
- write a fileje veux savoir comment je peux cree un fichier et ecrire sur lui le
resultats des tableau.......
merci
- 5
- Applet and browser pageHello, all !!!
I have HTML page with radio buttons.
And there is an applet on this page.
How can applet find out, radio selection ?
Thanx.
- 6
- Broken? <error-page> in web.xm under tomcat 4.xHello,
I am running Tomcat 4.x and have tried to set global error handling
using the following kind of entries in the web.xml file. But there is
no redirection and I always end up with the tomcat generated error
page in the browser.
Does anyone have a solution to this problem?
<error-page>
<error-code>500</error-code>
<location>/weberror.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/weberror.jsp</location>
</error-page>
Thanks
Bruce Sams
- 7
- graphical calendar viewHello,
It seems that the standard Java library doesn't include a graphical
calendar component so I was wondering if anyone happens to know of a
free one, preferably one that is big enough that would allow text to be
readable on the individual days (to list daily tasks, etc.)?
If there isn't one, any ideas on how I'd go about creating my own based
on the info from the existing java.util.Calendar object? I assume I
would probably need to have a JTable created at the least. Any
suggestions on doing that are appreciated.
thanks
Brandon
- 8
- cocoon : execute generated JSPHi folks,
I'm using cocoon-2.1.7 with Tomcat-5.5.9 on MacOS X
I created an XSP page that uses a logicsheet I wrote to generate JSP. I
need to get this JSP executed, but so far all I've been able to do is
have the JSP code outputed in the HTML doc.
My pipeline looks like this :
<map:match pattern="*.view">
<map:generate src="{1}.xsp" type="serverpages"/>
<map:serialize/>
</map:match>
After generating from my xsp source, I have a JSP doc ... how do I get
it executed before I serialize to HTML ? There are plenty of examples
when you generate with a JSP as a source doc, but not when I end up
with JSP in the pipeline.
[I trying to use java beans from within XSP. Since there's no
equivalent to <jsp:useBean> in xsp, I wrote a logicsheet that generates
and outputs the JSP tags I need.]
many thanks,
galpi
- 9
- 10
- good wysiwyg editor?Hello,
knows someone a good and easy to use wysiwyg editor for gui creating in
java? Or is it better to selfCode?
thanks for help
Patrick
- 11
- Problem setting Policy using Policy.setPolicyHi,
I'm trying to create my own Policy class and then set the policy to it
using Policy.setPolicy. Doing this doesn't seem to set the policy
correctly. However, if I call setPolicy twice instead of once it seems
to work correctly.
My test consists of trying to create a policy that will only allow
writing to a subdirectory and not to its parent directory. If I only
call setPolicy once, I can write to both the subdirectory and to the
parent directory. If I call setPolicy twice, then writing to the
parent directory causes a SecurityException as it should. The code
that I'm using is included below.
Is there something that I'm doing incorrectly?
Thanks in advance for your help,
Aaron
(I'm also posting this to Sun's "Security General" java forum)
----------
import java.io.IOException;
import java.io.File;
import java.io.FilePermission;
import java.security.CodeSource;
import java.security.PermissionCollection;
import java.security.Permissions;
import java.security.Policy;
import java.security.ProtectionDomain;
import java.io.FileWriter;
public class PT {
public static void main(String[] args) {
PT t2 = new PT();
}
public PT() {
// set up policy and security manager
MyPolicy mp = new MyPolicy();
// If you only set the policy once, for some reason it doesn't
// seem to really set the policy and lets you write to both
// the parent and sub directories. If you set the policy twice
// then it seems to work and does not let you write to the
// parent directory.
Policy.setPolicy(mp);
// uncomment the following line to get it to work
//Policy.setPolicy(mp);
System.setSecurityManager(new SecurityManager());
try {
// replace mydir with some appropriate directory
String name = "/mydir/test.txt";
System.out.println("trying to write to "+name);
File f2 = new File(name);
System.out.println("can write? "+f2.canWrite());
FileWriter fw = new FileWriter(name);
fw.write("abc");
fw.close();
System.out.println("wrote to "+name);
}
catch (Exception e) {
e.printStackTrace();
}
try {
// replace mydir and subdir with appropriate directories
String name = "/mydir/subdir/test.txt";
System.out.println("trying to write to "+name);
File f2 = new File(name);
System.out.println("can write? "+f2.canWrite());
FileWriter fw = new FileWriter(name);
fw.write("abc");
fw.close();
System.out.println("wrote to "+name);
}
catch (Exception e) {
e.printStackTrace();
}
}
private class MyPolicy extends Policy {
private Permissions p;
public MyPolicy() {
p = new Permissions();
// make mydir and subdir match the choices above
FilePermission fp = new FilePermission("/mydir/subdir/-",
"read,write,delete");
p.add(fp);
}
public PermissionCollection getPermissions(CodeSource cs) {
return p;
}
public void refresh() {
}
}
}
- 12
- GMailHi all,
Does anyone has invitation quota to GMail?
Seems it's a good webmail.
If you still have quota left, would you give me one?
My email is email***@***.com
Thanks.
- 13
- simple java question b=((1|2)^3)&5
acording to java cert book ans b =0
according to calculator b=1
does any one know why
ur answers will be highly apreciated
- 14
- ASM Help
I am trying to convert some asm to c. Learning asm as I go...
LINIT: .DB 38H ;
.DB 0CH ;
.DB 06H ;
LSIZZ .EQU $-LINIT ;
My question what is the LSOZZ equal?
- 15
- Icon designOn Fri, 23 Jul 2004 20:00:28 GMT, The Ghost In The Machine
<email***@***.com> wrote or quoted :
>Firefox has a fox circling the world
>but is visually slightly confusing, at least to me.
the small Firefox icon looks like a curled salamander.
Icon design is something I am battling on the current project I'm on.
I'm by far the oldest, and I like icons that are simple and
distinctive without a lot of fussy detail. I don't care if they are
abstract. I can learn what they mean with the hoverhelp and use even
peripheral vision to find them. The others are young. They like "cool"
icons that are highly representational. Yet to me, the icons all look
like complicated little miniature paintings. You can't tell what they
mean without squinting at them. I keep hitting the wrong one. The
product is aimed at grandmothers, but I think the others imagine
grandmothers are doddering and need the more literal icons rather than
having poor eyesight.
I would really like it if icons were configurable in all programs so
that if the authors make icons that all look alike to me, e.g. Funduc
Search/replace, I could fix them. The Opera people seem to have that
down to a science. I wish other companies would follow suit.
see http://mindprod.com/jgloss/opera.html
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
|
|