| Available memory and limit on thread creation |
|
 |
Index ‹ java-programmer
|
- Previous
- 1
- 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();
}
}
}
- 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
- 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());
}
}
- 3
- wholesale,hoody ( paypal accept ) ( www.top-saler.com ) wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
wholesale,hoody ( paypal accept ) ( www.top-saler.com
)
- 5
- 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
- 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) {}
}
- 6
- Stack and Thread SafetyMay I assume that a stack is thread safe since it extends the
synchronized vector class?
Thanks.
--
Kenneth P. Turvey <email***@***.com>
Artificial Intelligence Algorithms Wiki
http://ai.squeakydolphin.com
- 8
- 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
- 10
- Notifying ClientsHi,
I want my server to notify all the clients connected to it.
Basically the server should send the no. of files (count) in each
directories. I don't want the server to send this to each and every
client individually. This should be done in an efficient way.
Will JMS be used efficiently for this? or Is there any other way
to do this efficiently?
Thanks,
Ganesh
- 11
- Hel me! I'm going mad!!!Excuse me if I'm repetitive but I need help.
I thank Micheal Dunn but his suggestion is too particular and it's too
legates to a specific map of a museum.
I have this problem.
I have a map of a generic museum. Every room has maximum 4 links to other
room. These links have not a cost(the cost is always 1). I must implement a
algorithm to determinate the shortest path from a room to another room.
I have created a Class room, this class have these methods eand these data:
Method:
public int getNumVicini() //this method gives the number of room linked the
the object room in question;
public int getVicino(int v)//this method returns the 1st or the2nd or the
3rd or the 4th
public int getId()//return the id of the room
public String getPercorsi(int i)//return the path from the object room to
the room with id equals to i
public boolean verifyVicino(int v)//This method verify if a room with id
equals to v is linked to the object room
The there are the method addVicino(int i) that insert i inthe array vicini,
the method setname, setid, getname, getid etc.
Data:
private int vicini[]=new int[4];//this array contains the id of the linked
rooms
public String percorsi[]= new String[9];//this array contain the path from
the object room to all the others rooms in percorsi[0] there is the path
from object room to the room with id=0, in percrosi[1] path from object room
to the room with id[1], etc.
private int id;//in this int there's the id of the room
private String nome;//in this string there's the name of the room
In the main I have an array that contains all the room of the museum(Room
museum[]=new Room[x]).
The I have created a class Path to determinate the shortest path from a room
to another room.
This is the class Path:
public class Path {
private Room start;
public Path(Room r){ //the constructor take a room the room of start
and set the path to the linked room
for(int i=0; i<r.getNumVicini(); i++){
r.verifica[r.getVicino(i)]=true; //r.getVicino(i) give the id of
the linked rooms and set the verify[x], where x is the id of the linked
room, to true, because the shortest path is immediate
r.percorsi[r.getVicino(i)]+=r.getId()+ " " +
r.getVicino(i);//set the path to the linked room i equals to the id of the
start room an the id of the end room in this case the is of the end room is
the id a linked room
}
start=r;//it assigns the object r to start
}
private void findRoad2(Room end){ //this method permit to calculate
the path from 2 rooms that have a common linked room, but I don't know how
do to determinate a path for 2 room if between these 2 rooms there is more
of one room for example if I have these room 2-9-6-8(hte number are the id
of the room , the - are the link), with this method I am able to
derterminate the path from 2 to 9, from 2 to 6, but not for 2 to 8
for(int i=0; i<start.getNumVicini(); i++){
for(int j=0; j<end.getNumVicini(); j++){
if(start.getVicino(i)==end.getVicino(j) &&
start.verifica[end.getId()]==false){//This cycle verify if there is a common
linked room(like the room 9 in the example of the path from 2to6)
start.verifica[end.getId()]=true; //if there is this
common linked room it sets the verify[end.getId()] to true to indicate that
the path it is been determinated
start.percorsi[end.getId()]=start.getId()+ " " +
start.getVicino(i) + " " + end.getId(); //set the path, this path is equals
to start id and the id of the common linked room and end room id
}
}
}
}
If I have a map of the museum of this type:
7-8-3
| | |
6-4-2
| | |
5-0-1
(this map is only an example I could have a museum with 13 rooms that are
arranged in irregular way)
with the code that I have written I can determinate the path from 7 to 8,
from 7 to 6, from 7 to 4, from 7 to 3 and from 7 to 5, but NOT from 7 to 0,
from 7 to 1 or from 7 to 2
At the same way I can determinate the path from 0 to 5, from 0 to 1m from 0
to 4, from 0 to 8, from 0 to 2, from 0 to 6, but NOT from 0 to 3, from 0 to
7.
The some thing is for the rest of the rooms. I don't know how do to
determinate the rest of the path.
How can I do?
Thanks and excuse me.
- 13
- 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
- 13
- 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?
- 13
- 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.
- 14
- Oracle JDBC executeQuery() hanging with a to_char() in the selectCalling statement.executeQuery() hangs, anyone experienced this? Using
the Oracle thin driver v9.2.0.1.0 running on a Solaris 8 box. The
code:
Connection connection = cdrDataSource.getConnection();
Statement statement = connection.createStatement();
String sql = "SELECT
TO_CHAR(SOFIXML.SOFI_LIB.SOFI_GET_XML('CA89352LAC42', NULL, NULL))
FROM DUAL";
ResultSet resultSet = statement.executeQuery(sql);
if(resultSet.next()) {
return resultSet.getString(1);
}
The SOFI_GET_XML function returns a CLOB and I'm using TO_CHAR() to
convert is into a VARCHAR2 for speed. Not doing a TO_CHAR and
processing the CLOB works fine but is a little slow. The query runs
fine through both TOAD and SQLPlus.
Thanks, Chris
|
| Author |
Message |
Sudsy

|
Posted: 2004-7-3 10:04:00 |
Top |
java-programmer, Available memory and limit on thread creation
Joseph 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.
|
| |
|
| |
 |
Sudsy

|
Posted: 2004-7-3 10:04:00 |
Top |
java-programmer >> Available memory and limit on thread creation
Joseph 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.
|
| |
|
| |
 |
Roedy Green

|
Posted: 2004-7-3 10:26:00 |
Top |
java-programmer >> Available memory and limit on thread creation
On Fri, 02 Jul 2004 21:47:38 GMT, Joseph Dionne <email***@***.com>
wrote or quoted :
>The i/o is not the problem. The polling I speak of is monitoring the
>external, detached applications for their completion. Then I will need
>to send the results back to the correct socket.
If the problem is too many threads, you can reduce them by as the last
step of the exec stream you send a packet back to a common port where
the packet contain nothing but the id number of the exec. You might
even use a UDP protocol to avoid the overhead of setting up sockets.
When the "i'm done" packet comes in, you can look up the corresponding
object with a HashMap -- no thread or or socket at this point, and
move it to the next stage queue.
This sort of transaction processing was what we did back in the days
of minis with less than a meg of RAM. IBM's CICS was one the first of
these.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
| |
|
| |
 |
Joseph Dionne

|
Posted: 2004-7-3 10:52:00 |
Top |
java-programmer >> Available memory and limit on thread creation
Sudsy wrote:
> Joseph 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.
>
>
>
Thank you for your thoughtful reply. I assure you that I consider all
the advice Roedy offers. I find him a wealth of information.
I must confess, I am new to Java, and only have a cursory knowledge of
web development. Unfortunately my delivery date is very tight, tighter
than the learning curve needed to explore too much new technology. My
customer base gives me access to many different hardware and OS
platforms, and I have found this limit I am experiencing seems isolated
to Linux. However, every problem has a solution, and I have several
options to overcome this current opportunity.
Throughput is the highest concern. I estimate hits in the thousands so
I must be careful not to add to much processing overhead. The choice of
language was part of the contract, and I always love a challenge. Besides,
Thanks to everyone who offered advice, it is greatly appreciated.
Joseph
|
| |
|
| |
 |
Joseph Dionne

|
Posted: 2004-7-3 10:59:00 |
Top |
java-programmer >> Available memory and limit on thread creation
Roedy Green wrote:
> On Fri, 02 Jul 2004 21:47:38 GMT, Joseph Dionne <email***@***.com>
> wrote or quoted :
>
>
>>The i/o is not the problem. The polling I speak of is monitoring the
>>external, detached applications for their completion. Then I will need
>>to send the results back to the correct socket.
>
>
> If the problem is too many threads, you can reduce them by as the last
> step of the exec stream you send a packet back to a common port where
> the packet contain nothing but the id number of the exec. You might
> even use a UDP protocol to avoid the overhead of setting up sockets.
>
> When the "i'm done" packet comes in, you can look up the corresponding
> object with a HashMap -- no thread or or socket at this point, and
> move it to the next stage queue.
>
> This sort of transaction processing was what we did back in the days
> of minis with less than a meg of RAM. IBM's CICS was one the first of
> these.
>
>
First, I need to test the use of Linux virtual ip as a potential
solution. This will allow me to have four VMs accepting connections on
a single CPU, and I can sell the customer a multiple NIC card to improve
IP traffic even more.
Second, using the typical consumer/producer model, allocate general
purpose socket readers in a pool, another pool to process the received
packets, and a third pool to manage the external application execution.
One question that I could use advice, is it possible to use Channels for
Process management? My thought is to monitor the output stream of the
Process for OP_READ, and wait for EOF when the process terminates. Any
flaws in my thought?
Joseph
|
| |
|
| |
 |
Roedy Green

|
Posted: 2004-7-3 11:17:00 |
Top |
java-programmer >> Available memory and limit on thread creation
On Sat, 03 Jul 2004 02:58:53 GMT, Joseph Dionne <email***@***.com>
wrote or quoted :
>One question that I could use advice, is it possible to use Channels for
>Process management? My thought is to monitor the output stream of the
>Process for OP_READ, and wait for EOF when the process terminates. Any
>flaws in my thought?
One area I still have not explored is nio. I have done such things at
very low level poking hardware devices, but not with the nio package.
My thinking is warped by what the hardware can typically do.
I think back to a ferry reservation system for the BC Government. I
worked with guy who was one of the designers of IBM's channel
architecture and decided to implement the system with astounding
throughput by making the channel (a sort of smart DMA controller) do
much of the work. I thought he was mad. Yet I had to admit, he got
throughput orders of magnitude better than he could have with a more
general solution on what we would consider a tiny machine today. He
did not do everything this way, just the few crucial transactions that
made the overwhelming bulk.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
| |
|
| |
 |
Roedy Green

|
Posted: 2004-7-3 11:27:00 |
Top |
java-programmer >> Available memory and limit on thread creation
On Sat, 03 Jul 2004 02:51:45 GMT, Joseph Dionne <email***@***.com>
wrote or quoted :
>
>I must confess, I am new to Java, and only have a cursory knowledge of
>web development. Unfortunately my delivery date is very tight, tighter
>than the learning curve needed to explore too much new technology.
My reaction in this deadline environment is to go a little LOWER level
than I would otherwise. I am better off to write code that uses a
smaller subset of tools, but ones that I fully understand.
Using a high level tool presents endless surprises because it takes
years to fully understand it. Further, there is no guarantee it will
sit still. You may have to KEEP dancing to KEEP your code working.
Further the package could deteriorate or lose support. So often you
are working with a black box. Even with source, only the original
developers or someone who makes a full time job of learning the source
can find their way around to track problems. If the code is buggy, you
are better off with the smaller more specialised solution you wrote
yourself. On the other hand, with a commonly used tool, there are
others who can help you track problems.
So, when I want to be sure it will work, I like to have as much of the
code under my personal control as possible. Other people's code gives
me at least ten times more trouble than my own. The main reason is I
can understand my own documentation and I tend to document that which
I know I will want to know later.
If you are starting out on what you know will be a very large project
that will go on for years, maintained by many different people, then
you want to take some time to find some good high level tools,
preferably ones with alternate sources.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
| |
|
| |
 |
Joseph Dionne

|
Posted: 2004-7-3 11:29:00 |
Top |
java-programmer >> Available memory and limit on thread creation
Roedy Green wrote:
> On Sat, 03 Jul 2004 02:58:53 GMT, Joseph Dionne <email***@***.com>
> wrote or quoted :
>
>
>>One question that I could use advice, is it possible to use Channels for
>>Process management? My thought is to monitor the output stream of the
>>Process for OP_READ, and wait for EOF when the process terminates. Any
>>flaws in my thought?
>
>
> One area I still have not explored is nio. I have done such things at
> very low level poking hardware devices, but not with the nio package.
>
[snip]
I have been watching Java develop since '96. I avoided it even though I
admired the effort for several reasons. But 1.4 has changed my
thinking, and the nio package has addressed my last concern, moving back
towards multiplex technology. The package allows an alternative to
launching threads for each new client, a time consuming process.
I am very impressed with Java, and for my business, a language that
allows me to develop on my favorite OS/hardware and deploy on so many
others without porting is ideal.
I need to get up to speed on JSP and Struts, which opens up even more
opportunities. I commend Sun for bring to the community of developers a
platform that encourages the exchange of ideas, replacing the isolation
we have had for so many years.
Joseph
|
| |
|
| |
 |
Roedy Green

|
Posted: 2004-7-3 11:43:00 |
Top |
java-programmer >> Available memory and limit on thread creation
On Sat, 03 Jul 2004 02:51:45 GMT, Joseph Dionne <email***@***.com>
wrote or quoted :
>Throughput is the highest concern.
I always wanted some sort of animation tool so you could watch data
flowing. You would watch a typical transaction flowing through the
system. Visual representations of Objects would bloat up to represent
their relative RAM use. Time delay would match CPU or other resource
usage.
Watching endless repetitions of this would quickly point out where you
are being "silly".
It would be sort of like taking a tour of a Coke bottling factory,
watching the entire process from various vantage points.
The sort of things you would notice is carefully setting up a socket
then throwing it away and creating another just like it. Huge numbers
of objects lying around doing nothing. Huge amounts of information
endlessly repeated.
You can get a bit of a feel by doing an assembler level trace and
watching the incredible overhead of method calls, the endless buck
passing.
There are two kinds of programmers, those anal retentive types to try
to optimise everything whether it needs it or not, in the process
making the code hard to read, and programmers terrified to do ANYTHING
out of the usual, even if one line done a slightly odd way will give
you a 100 fold increase in speed. They are anally retentive in wanting
everything done in a uniform way, and feel than any sort of
optimisation is evil unless done at gunpoint and only after you did it
some klutzy way first. They flatly refuse to think about what is
happening under the covers and pride themselves on making non-optimal
choices even when both are equally easy to code. They misunderstand
Knuth's admonition that premature optimisation is the root of all
evil. They think that means you should not think about optimisation
until after the product has shipped. It has a place before you even
write a line of code, in choosing the best data structures and
algorithms. You just should not do anything tricky without proof it
is needed.
There are few non-anal retentives in programming. They are soon fired.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
| |
|
| |
 |
Joseph Dionne

|
Posted: 2004-7-3 11:59:00 |
Top |
java-programmer >> Available memory and limit on thread creation
Roedy Green wrote:
[snip]
> There are two kinds of programmers, those anal retentive types to try
> to optimise everything whether it needs it or not, in the process
> making the code hard to read, and programmers terrified to do ANYTHING
> out of the usual, even if one line done a slightly odd way will give
> you a 100 fold increase in speed.
I guess I fall into a place between the two, an acute case of
hemorrhoids. I began life creating circuit cards, and years working in
assembler, until c arrived on the scene. Even in c I had to do some
optimization, buy only at the points where I would get the greatest bang
for the buck. The reality of software development is to consider the
future maintenance. Code that is difficult to understand will die a
quite death, neglected when the author loses interest. Code that is
easy to understand will live on, being extended to fit the needs of the day.
Joseph
|
| |
|
| |
 |
kjc

|
Posted: 2004-7-3 23:43:00 |
Top |
java-programmer >> Available memory and limit on thread creation
JBoss is free
Joseph Dionne wrote:
> Sudsy wrote:
>
>> Roedy Green wrote:
>> <snip>
>>
>>> Even if there is, you don't necessarily have to have a thread sit and
>>> wait for the exec. You could do something like have the spawned stuff
>>> report back when done through some other queuing mechanism.
>>>
>>> The key is to reuse threads and keep them busy. The only reason they
>>> should sleep, is when they are waiting a few milliseconds for a disk
>>> i/o. If they have to sleep longer than that, think about keeping track
>>> of their state some other way. There are natural breaking points in
>>> thread's life where it's state can be very compactly described. It
>>> can be put into hibernation so to speak as a simple object, and
>>> instantly awakened by some other already-running thread.
>>
>>
>>
>> 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!
>
|
| |
|
| |
 |
kjc

|
Posted: 2004-7-3 23:48:00 |
Top |
java-programmer >> Available memory and limit on thread creation
Sounds like you're going to be writing an AppServer.
Joseph Dionne wrote:
> Roedy Green wrote:
>
> [snip]
>
>> There are two kinds of programmers, those anal retentive types to try
>> to optimise everything whether it needs it or not, in the process
>> making the code hard to read, and programmers terrified to do ANYTHING
>> out of the usual, even if one line done a slightly odd way will give
>> you a 100 fold increase in speed.
>
>
> I guess I fall into a place between the two, an acute case of
> hemorrhoids. I began life creating circuit cards, and years working in
> assembler, until c arrived on the scene. Even in c I had to do some
> optimization, buy only at the points where I would get the greatest bang
> for the buck. The reality of software development is to consider the
> future maintenance. Code that is difficult to understand will die a
> quite death, neglected when the author loses interest. Code that is
> easy to understand will live on, being extended to fit the needs of the
> day.
>
> Joseph
>
|
| |
|
| |
 |
John C. Bollinger

|
Posted: 2004-7-6 5:46:00 |
Top |
java-programmer >> Available memory and limit on thread creation
Joseph Dionne wrote:
> Roedy Green wrote:
>
>> On Sat, 03 Jul 2004 02:58:53 GMT, Joseph Dionne <email***@***.com>
>> wrote or quoted :
>>
>>
>>> One question that I could use advice, is it possible to use Channels
>>> for Process management? My thought is to monitor the output stream
>>> of the Process for OP_READ, and wait for EOF when the process
>>> terminates. Any flaws in my thought?
>>
>>
>>
>> One area I still have not explored is nio. I have done such things at
>> very low level poking hardware devices, but not with the nio package.
>>
> [snip]
>
> I have been watching Java develop since '96. I avoided it even though I
> admired the effort for several reasons. But 1.4 has changed my
> thinking, and the nio package has addressed my last concern, moving back
> towards multiplex technology. The package allows an alternative to
> launching threads for each new client, a time consuming process.
So, then, why aren't you multiplexing your socket listening? That would
save you a whole lot of threads. You would want to look into the
Selector class, which, with some associated classes, provides more or
less an OO version of C's select() function.
You wrote earlier that the back-end app does not make use of stdin /
stdout / stderr to communicate with the caller. Can you wrap it in a
script or other wrapper program that will adapt it to do so? I think
that would allow you to use NIO to multiplex monitoring of the state of
the back-end process invocations as well, hence giving you an entry into
implementing some of the suggestions Roedy has been offering.
It really should not be necessary to spawn hundreds of threads for an
application like this. Much as Roedy already said, it is probably not
very useful to launch more than a handful of threads if you have a way
to use that handful to perform all the needed work.
John Bollinger
email***@***.com
|
| |
|
| |
 |
Joseph Dionne

|
Posted: 2004-7-7 2:44:00 |
Top |
java-programmer >> Available memory and limit on thread creation
John C. Bollinger wrote:
> Joseph Dionne wrote:
>
>> Roedy Green wrote:
>>
>>> On Sat, 03 Jul 2004 02:58:53 GMT, Joseph Dionne <email***@***.com>
>>> wrote or quoted :
>>>
>>>
>>>> One question that I could use advice, is it possible to use Channels
>>>> for Process management? My thought is to monitor the output stream
>>>> of the Process for OP_READ, and wait for EOF when the process
>>>> terminates. Any flaws in my thought?
>>>
>>>
>>>
>>>
>>> One area I still have not explored is nio. I have done such things at
>>> very low level poking hardware devices, but not with the nio package.
>>>
>> [snip]
>>
>> I have been watching Java develop since '96. I avoided it even though
>> I admired the effort for several reasons. But 1.4 has changed my
>> thinking, and the nio package has addressed my last concern, moving
>> back towards multiplex technology. The package allows an alternative
>> to launching threads for each new client, a time consuming process.
>
>
> So, then, why aren't you multiplexing your socket listening? That would
> save you a whole lot of threads. You would want to look into the
> Selector class, which, with some associated classes, provides more or
> less an OO version of C's select() function.
>
Actually, as I have said before, I am using channels for socket
management, and assigning new connections to a connection pool of
created client threads.
> You wrote earlier that the back-end app does not make use of stdin /
> stdout / stderr to communicate with the caller. Can you wrap it in a
> script or other wrapper program that will adapt it to do so? I think
> that would allow you to use NIO to multiplex monitoring of the state of
> the back-end process invocations as well, hence giving you an entry into
> implementing some of the suggestions Roedy has been offering.
>
Now, I have explored the NIO library, but have not found a
ProcessChannel that monitors a Process, nor a implementation of a
StreamChannel. To implement either as a channel for SelectableChannel I
would need more threads to watch the Process streams. I want to use
blocking threads, to not needlessly eat CPU time, so I would need a
thread per "transaction," or connection in my case. Thus I would need
even more threads.
> It really should not be necessary to spawn hundreds of threads for an
> application like this. Much as Roedy already said, it is probably not
> very useful to launch more than a handful of threads if you have a way
> to use that handful to perform all the needed work.
>
And, you are correct. one thread can handle any number of requests, if
the remote clients are willing to wait to be service. However, as I
have also said, throughput is critical. The remote clients will not
wait long, perhaps five to ten seconds, before the connection is aborted
from the peer. Since the remote client MUST communicate via my
application, to get real work done, aborted connections will result in a
new, quickly generated, connect attempt, and another socket to service,
while the old socket, perhaps waiting in a queue for processing, is now
dead. This potential will only add to the burden of the application I
am creating.
But, if you have suggestion for using NIO channels to monitor Process
object, I would be greatly interested in your input. I have confirmed
that on most OS/hardware I have access to, I can create the desired
number of threads. The problem seems to be localized to Linux, and I
believe MIGHT be a kernel setting, however I have already ruled out
threads-max. On some Linux systems I have tested, I am unable to even
launch the 1015 threads I can on my development system.
Additionally, I have tried JVM 1.5.0(beta), and found that by using the
"-Xprof" option, the limit did not appear, yet without that option, I
still got a 1015 thread limit. I was hoping someone from Sun monitors
this group, and would perhaps offer a reason for the limit I am noticing
on Linux ONLY.
>
> John Bollinger
> email***@***.com
|
| |
|
| |
 |
Joseph Dionne

|
Posted: 2004-7-7 3:28:00 |
Top |
java-programmer >> Available memory and limit on thread creation
Joseph Dionne wrote:
> I am using Linux 2.4 with JVM 1.4.2_04. I have noticed a limit to the
> number of threads that can be created. I tried many settings of "-Xmx"
> and "-Xss" and the largest number of threads I can launch is 1015. So,
> I have several questions.
>
> First, does available memory limit number of threads?
> Second, if available memory does limit the number of threads, is there a
> rule of thumb on how to calculate that limit?
> Finally, exactly what affect do "-Xmx" and "-Xss" have to the VM and do
> they affect thread memory at all?
>
> thanks
> Joseph
>
For other people having problems starting thousands of threads from Java
with Linux, the following kernel parameters will limit the number of
threads, and result in an OutOfMemoryError.
/proc/sys/kernel/threads-max <int value>
/proc/sys/kernel/rtsig-max <int value>
While threads-max might be large enough, I have found rtsig-max set very
low, on my system it was set to 1024 even though my threads-max was set
to 8184. I do not know what, is any, relationship exists between the
two values. On some linux systems, installed "out-of-the-box" so to
speak, these values can be very low.
Thanks to all that provided input to my request. Your thoughts and
suggestions are very appreciated.
Joseph
|
| |
|
| |
 |
Andrew Thompson

|
Posted: 2004-7-7 3:36:00 |
Top |
java-programmer >> Available memory and limit on thread creation
On Tue, 06 Jul 2004 18:44:14 GMT, Joseph Dionne wrote:
> I was hoping someone from Sun monitors
> this group, and would perhaps offer a reason
> for the limit I am noticing on Linux ONLY.
Posting to this group sounds like a strange
way to to go about getting a response from Sun.
They have specialized forums of their
own, bug reports, contact forms..
This, in contrast, is 'the jungle'.
--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
|
| |
|
| |
 |
marcus

|
Posted: 2004-7-7 8:35:00 |
Top |
java-programmer >> Available memory and limit on thread creation
OK, I did not read all the replies (most of them over my head!), so this
might have been covered . . .
Your idea of using virtual IP's or another mechanism to run multiple
JVM's seems sound for various reasons. You mentioned server farms,
which indicates you will need to do some amount of distributed
processing eventually anyway, so the logic of distributing the load will
not change dramatically from multiple JVM's or multiple machines.
I use apache to handle connect to tomcat through mod_jk, which specifies
an internal port (JkMount /shop/servlet/* ajp12). It is easy enough for
apache to mount to multiple internal ports using their virtual server
based on the domain of the request, so I wouldn't have to mess with IP's
or even ports (mydomain.com:8080).
Since you already have load balancing in the final equasion, it seems to
me the load balancer could be configured to make requests on
loader1.mydomain.com, loader2.mydomain.com, etc, which transparently
point to separate boxes or separate JVM's on a given box, and you can
deal with the fine points of balancing and maxamising server usage (also
over my head *grin*) when the load is actually present.
(My internal editor suggests the load balancer might have to resort to
rewriting to specific ports like loader1.mydomain.com:8081 and you may
have to configure various apps to start and run listening on
corresponding ports, rather than having another app like apache
distributing requests, but that seems trivial.)
-- clh
Joseph Dionne wrote:
> I am using Linux 2.4 with JVM 1.4.2_04. I have noticed a limit to the
> number of threads that can be created. I tried many settings of "-Xmx"
> and "-Xss" and the largest number of threads I can launch is 1015. So,
> I have several questions.
>
> First, does available memory limit number of threads?
> Second, if available memory does limit the number of threads, is there a
> rule of thumb on how to calculate that limit?
> Finally, exactly what affect do "-Xmx" and "-Xss" have to the VM and do
> they affect thread memory at all?
>
> thanks
> Joseph
>
|
| |
|
| |
 |
John C. Bollinger

|
Posted: 2004-7-8 1:09:00 |
Top |
java-programmer >> Available memory and limit on thread creation
Joseph Dionne wrote:
> John C. Bollinger wrote:
>
>> You wrote earlier that the back-end app does not make use of stdin /
>> stdout / stderr to communicate with the caller. Can you wrap it in a
>> script or other wrapper program that will adapt it to do so? I think
>> that would allow you to use NIO to multiplex monitoring of the state
>> of the back-end process invocations as well, hence giving you an entry
>> into implementing some of the suggestions Roedy has been offering.
>>
>
> Now, I have explored the NIO library, but have not found a
> ProcessChannel that monitors a Process, nor a implementation of a
> StreamChannel. To implement either as a channel for SelectableChannel I
> would need more threads to watch the Process streams.
You're quite right; I had misremembered some of the NIO details. I was
thinking that you could get a SelectableChannel from System.in, which
would then not have required additional threads, but it doesn't look
like that is possible. My apologies.
The general idea may still be applicable, however: if you wrap the
back-end such that it reports task completion by communicating over a
socket to your middleware application then you certainly can use NIO to
multiplex those notifications, as both SocketChannel and
ServerSocketChannel implement SelectableChannel.
So how _does_ the back end report that it has finished a task, anyway?
> I want to use
> blocking threads, to not needlessly eat CPU time, so I would need a
> thread per "transaction," or connection in my case. Thus I would need
> even more threads.
You certainly want to avoid putting threads into idle loops, but having
many blocking threads is not the only alternative. Roedy has already
covered this ground, though, and you don't seem to have a problem with
the concept -- except that you keep insisting that you don't want to do
the job that way.
>> It really should not be necessary to spawn hundreds of threads for an
>> application like this. Much as Roedy already said, it is probably not
>> very useful to launch more than a handful of threads if you have a way
>> to use that handful to perform all the needed work.
>>
>
> And, you are correct. one thread can handle any number of requests, if
> the remote clients are willing to wait to be service. However, as I
> have also said, throughput is critical. The remote clients will not
> wait long, perhaps five to ten seconds, before the connection is aborted
> from the peer. Since the remote client MUST communicate via my
> application, to get real work done, aborted connections will result in a
> new, quickly generated, connect attempt, and another socket to service,
> while the old socket, perhaps waiting in a queue for processing, is now
> dead. This potential will only add to the burden of the application I
> am creating.
The server has a limited capacity to perform work. If the server cannot
adequately accommodate the demand on its resources then using more
threads will not fix the problem -- threads that are runnable (i.e. not
blocked) but not currently running do not increase or make any better
use of the server's capacity. Indeed, you may incur a noticeable
overhead in the thread scheduler when there are many runnable threads
contending for CPU time. The number of threads required to sufficiently
minimize the likelihood that they may all be blocked at the same time
will depend on the application, hardware, and OS, but that is the number
of threads you should be shooting for to tune the application's
performance. Much of this discussion has been aimed at approaches to
designing the application so that the required number is as small as
possible while at the same time ensuring that the application itself is
as responsive as possible. These are compatible goals.
> But, if you have suggestion for using NIO channels to monitor Process
> object, I would be greatly interested in your input.
You don't necessarily need to monitor the Process object itself. Ideal
would be to arrange so that the native process actively notifies your
application when it is done. Some of my comments above were directed at
enabling that. Such a scenario could allow you to multiplex the
monitoring, thus requiring fewer threads and possibly yielding a
performance improvement over your preferred approach of using a large
number of dedicated threads. It evidently would make your application
more portable, too.
John Bollinger
email***@***.com
|
| |
|
| |
 |
Michael Borgwardt

|
Posted: 2004-7-9 16:14:00 |
Top |
java-programmer >> Available memory and limit on thread creation
Joseph Dionne wrote:
> For other people having problems starting thousands of threads from Java
> with Linux, the following kernel parameters will limit the number of
> threads, and result in an OutOfMemoryError.
>
> /proc/sys/kernel/threads-max <int value>
> /proc/sys/kernel/rtsig-max <int value>
>
> While threads-max might be large enough, I have found rtsig-max set very
> low, on my system it was set to 1024 even though my threads-max was set
> to 8184. I do not know what, is any, relationship exists between the
> two values.
Looking around a bit, the second doesn't seem directly related to threads; it
limits the number of "realtime signals " that can be queued. I suppose that
a blocked thread takes up one such queue slot.
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- 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?
- 2
- 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.
- 3
- 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.
- 4
- 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() {
}
}
}
- 5
- 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
- 6
- 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.
- 7
- 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
- 8
- 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
- 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
- 10
- 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
- 11
- 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
- 12
- 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.
- 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
- 15
- 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
|
|
|