 |
 |
Index ‹ java-programmer
|
- Previous
- 1
- Java compiler with inline bytecode?Does anyone know of a java compiler that allows inline "java assembly
mnemonics" to be included in amongst the standard java code?
Similar to the inline asm keyword in C/C++ compilers...
Cheers :o)
Will
- 1
- Reflection with Java and Oracle 10gHi everyone,
We have change oracle 8i to oracle 10g, now we have problems with the
reflection in JAVA.
I've got an IllegalAccessException:
Object value;
value = infoResultSetAndData.getResultSetMethodGet().invoke(rs, new
Object[] {new Integer(infoResultSetAndData.getResultSetIndice())});
thanks for suggestions,
fourmi
- 5
- java.security.NoSuchAlgorithmException: No such algorithm: RSAI have this code
import java.io.*;
import java.security.*;
import javax.crypto.*;
class Encrypt {
private Cipher RSAtransform;
public Encrypt()
{
Provider rsajca = new com.sun.rsajca.Provider();
Security.addProvider(rsajca);
try
{
RSAtransform = Cipher.getInstance("RSA",rsajca);
}
catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
catch (NoSuchPaddingException e) {
e.printStackTrace();
}
}
...
...
But when I run it on winxp (using Java 1.4.2) I get:
java.security.NoSuchAlgorithmException: No such algorithm: RSA
at javax.crypto.SunJCE_b.c(DashoA6275)
at javax.crypto.SunJCE_b.a(DashoA6275)
at javax.crypto.Cipher.a(DashoA6275)
at javax.crypto.Cipher.getInstance(DashoA6275)
at keys.Encrypt.<init>(Encrypt.java:18)
at keys.Encrypt.main(Encrypt.java:115)
java.lang.NullPointerException
at keys.Encrypt.encrypt(Encrypt.java:73)
at keys.Encrypt.main(Encrypt.java:128)
Why is it not possible to use the RSA algorithm?
I would prefer to use an asymmetric algorithm instead of DES.
Hope someone can help
JOhs
- 6
- modeling possible polymorphism?hi..
i have entity called AssuredPerson and entity called PolicyOwner, both
have similar attributes (meaning Abstract Person Class)
however an AssuredPerson can be PolicyOwner (but not the way around).
so i've added a property called isPolicyHolder (boolean) to
AssuredPerson.
is this correct way to go about it?
- 6
- How to load INI file to JTree Nodes?Hi,
I am new to JAVA SWING and would like someone to help me out here.
I need to read the INI file to load out the structure and display them
on the JTree.
How can I go about doing that?
The INI file format looks like following:
[R]
ChildsCount = 2
C1 = Enclosure(s)
C2 = JBOD(s)
[R\C1]
ChildsCount = 2
C1 = EnclosureWWN A
C2 = EnclosureWWN B
[R\C1\C1]
ChildsCount = 6
C1 = Power Supply
C2 = Fan
C3 = Battery
C4 = Numeric Sensor
C5 = Controller
C6 = Device Group(s)
[R\C1\C1\C1]
ChildsCount = 2
C1 = PSU0
C2 = PSU1
[R\C1\C1\C2]
ChildsCount = 2
C1 = Fan0
C2 = Fan1
[R\C1\C1\C3]
ChildsCount = 2
C1 = UPS
C2 = Motherboard
[R\C1\C1\C4]
ChildsCount = 3
C1 = NS0
C2 = NS1
C3 = NS2
[R\C1\C1\C5]
ChildsCount = 2
C1 = ControllerWWN A
C2 = ControllerWWN B
[R\C1\C1\C6]
ChildsCount = 7
C1 = Device Group A
C2 = Device Group B
C3 = Device Group C
C4 = Device Group D
C5 = Device Group E
C6 = Device SubGroup A
C7 = Device SubGroup B
[R\C1\C1\C6\C1]
ChildsCount = 3
C1 = Volume 1
C2 = Volume 2
C3 = Volume 3
[R\C1\C1\C6\C1\C1]
ChildsCount = 2
C1 = LUN0
C2 = LUN1
[R\C1\C1\C6\C1\C1\C1]
ChildsCount = 4
C1 = Host A
C2 = Host B
C3 = Host C
C4 = Host D
[R\C1\C1\C6\C1\C1\C2]
ChildsCount = 2
C1 = Host A
C2 = Host C
In the JTree it should shows something like this:
Enclosure(s)
|__EnclosureWWN A
|__Power Supply
|__PSU0
|__PSU1
|__Fan
|__Battery
|__Numeric Sensor
|__Controller
|__Device Group(s)
|__EnclosureWWN B
- 7
- MyCalendar subclass and threadingI have an application that deals with alot of dates, I have classes that
represent time & duration. I do not need to cart around the beast that is
GregorianCalendar.
However I do need to use it to convert data.
eg:
gregCal.setTime(myDate);
gregCal.get(Calendar.DATE);
gregCal.get(Calendar.MONTH_OF_YEAR); // etc
Also I really need a different Calendar, something that I can do this with
myCal.isSpecialDay();
So I'm wondering whether I should subclass Calendar/Gregorian to add my
special dates.
Because I don't see the need to have an instance of this in my time/duration
objects, I'm thinking, I could have a Singleton MyCalendar to use for look
ups.
At present there isn't a threading issue, just one thread. But I'd like to
make it thread safe, none the less. Also if there are multiple threads
eventually, I should convert my Singleton to an Object pool - right?
Anyhow I'd need to synchronise over several calls within MyCalendar to make
sure the date is setup and retrieved correctly:
synchronized public boolean isSpecialDay(Date date) {
setTime(date);
return isSpecialDay();
}
Presumably I should make all methods that set the date synchronized also?
I know there is probably some bad stuff above, how should I do this please?
--
Mike W
- 7
- A java network sniffer for WindowsHi everybody,
If you want to listen or publish Ethernet packet with Java, please try
Jiffer.
You can download Jiffer here : http://aroche.free.fr
If you have any suggestion or experience problem to install Jiffer
please contact.
Have fun !!
Arnaud ROCHE
- 8
- java.lang.NullPointerException at com.sun.kvem.midp.MIDP.run(MIDP.java:651)Hi Friends,
Does any one has any idea about the following StackTrace. I am using
CLDC1.1 and MIDP2.0 with Sun Java Studio Mobility. Any help will be
highly appreciated.
java.lang.NullPointerException
at com.sun.kvem.midp.MIDP.run(MIDP.java:651)
at
com.sun.kvem.environment.EmulatorInvoker.runEmulatorImpl(EmulatorInvoker.java:116)
at
com.sun.kvem.environment.EmulatorInvoker.runEmulatorSameVM(EmulatorInvoker.java:105)
at
com.sun.kvem.environment.EmulatorInvoker.runEmulator(EmulatorInvoker.java:63)
at com.sun.kvem.environment.ProfileEnvironment$KVMThread.runEmulator
(ProfileEnvironment.java:240)
at
com.sun.kvem.environment.ProfileEnvironment$KVMThread.run(ProfileEnvironment.java:262)
Greetings,
- 8
- Custom JComponent: add to contentPaneHello,
I created a custom JComponent which consists of two JTables on a
JScrollPane.
My problem is when I add a JDividedTable instance to the content pain of a
JFrame,
I only see a grey frame with the preferredSize of the scrollpane of my
custom component.
When I pass the contentPane of the Frame to the constructor of
JCustomComponent
and contentPane.add(scrollPane) call at the end everything works fine.
The solution with the contentPane as parameter in the constructor is not
desirable in thougths of
reusability and flexibility.
Can anybody tell me what is wrong?
I want to use it like this from a JFrame, for example:
public class MyApp extends JFrame {
public MyApp() {
Container cp = getContentPane();
....
JDividedTable dividedTable = new JDividedTable(someModel,3);
cp.add(dividedTable);
...
}
public static void main ....
In JCustomComponent I override set getter and setter methods for the
preferred, maximum and minimum
size of JComponent.
Here is the source of my Component:
-------------------------------------------------------------------------
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.accessibility.AccessibleContext;
import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**This swing UI class provides a
* {@link javax.swing.JTable JTable} in a {@link javax.swing.JScrollPane
* JScrollPane} with fixed columns on the left side and
* horizontal scrollable columns on the right side. The number of fixed
* columns is user defined within the constructor.<br><br>
*
* The divided table is constructed out of two JTable's with the same
* TableModel. The fixed table is installed as RowHeaderView on the
* JScrollPane. From the scrollable table's TableColumnModel the
* first <code>fixedCols</code> are removed.
*
*/
public class JDividedTable extends JComponent {
private static final Log log = LogFactory.getLog(JDividedTable.class);
/* ==================================================================== */
/**
* Cronstructs a <code>JDividedTable</code> in a <code>JScrollPane</code>
* with a number of <code>fixedCols</code> on the left.
*
* @param dm The underlying tableModel of this table.
* @param fixedCols The number of fixed columns on the left side.
* @param contentPane The container the table should be installed on.
*/
public JDividedTable(TableModel dm, int fixedCols, Container contentPane)
{
fixedColumns = fixedCols;
initDividedTable(dm, null);
removeFixedColsFromScrollableTable();
synchronizeSelection();
putTablesOnContainer(contentPane);
}
/* ==================================================================== */
/**
* Cronstructs a <code>JDividedTable</code> in a <code>JScrollPane</code>
* with a number of <code>fixedCols</code> on the left. The data are
* arranged according to <code>sorter</code> if a sorter is provided.
*
* @param dm The underlying tableModel of this table.
* @param fixedCols The number of fixed columns on the left side.
* @param sorter A custom sorter (optional).
* @param contentPane The container the table should be installed on.
*/
public JDividedTable(TableModel dm, int fixedCols, AbstractSortDecorator
sorter,
Container contentPane) {
fixedColumns = fixedCols;
initDividedTable(dm, sorter);
removeFixedColsFromScrollableTable();
synchronizeSelection();
putTablesOnContainer(contentPane);
}
/* ==================================================================== */
/**Gets the actual sort decorator.
* @return The sort decorator.
*/
public AbstractSortDecorator getSortDecorator () {
return customSorter;
}
/* ==================================================================== */
/**Adds a new <code>AbstractSortDecorator</code> to the divided table.
* @param sorter The new sort decorator.
* @throws IllegalArgumentException If sorter is null.
*/
public void setSortDecorator(AbstractSortDecorator sorter)
throws IllegalArgumentException{
if (sorter == null) {
log.error("AbstractSortDecorator can't be set to 'null'");
throw new IllegalArgumentException("AbstractSortDecorator " +
"can't be set to 'null'");
} else {
if (log.isInfoEnabled()) {
log.info("Adding a sorter to the divided table: '" +
sorter + "'");
}
customSorter = sorter;
fixedTable.setModel(customSorter);
scrollableTable.setModel(customSorter);
removeFixedColsFromScrollableTable();
setMouseListenerToHeader(false);
}
}
/* ==================================================================== */
/**Allows to reorder interactively the columns in the scrollable table
* if <code>allowed</code> is true.
* @param allowed Allow reordering of columns? Per default it is set to
true.
*/
public void setHeaderReorderingAllowed(boolean allowed) {
scrollableTable.getTableHeader().setReorderingAllowed(allowed);
}
/* ==================================================================== */
/**Sets the mouse listeners for the table headers of both tables for the
* sorter and synchronizes both models. When the listener is set to true
* the user can sort the table interactively by clicking on the table
* headers. If it is set to false, the table is sorted according
* to the fixed sort criteria defined in the sorter.<br>
* The default for the divided table is 'listeners off'.<br>
* After a mouseClicked event both tables needs to be repainted because
* otherwise their were problems encountered with updating of the two
* table components.
*
* @param mouseListenerOn Set or remove the listener to/from the headers,
* per default it is set to false. It only adds a
* listener if the divided table has a sorter.
*/
public void setMouseListenerToHeader(boolean mouseListenerOn) {
JTableHeader fixedHdr = (JTableHeader) fixedTable.getTableHeader();
JTableHeader scrollableHdr = (JTableHeader)
scrollableTable.getTableHeader();
MouseListener fixedListener = null;
MouseListener scrollableListener = null;
if ((mouseListenerOn == true) && (customSorter != null)) {
fixedListener = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
TableColumnModel tcm = fixedTable.getColumnModel();
int vc = tcm.getColumnIndexAtX(e.getX());
int mc = fixedTable.convertColumnIndexToModel(vc);
customSorter.sort(mc);
fixedTable.repaint();
scrollableTable.repaint();
}
};
fixedHdr.addMouseListener(fixedListener);
scrollableListener = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
TableColumnModel tcm = scrollableTable
.getColumnModel();
int vc = tcm.getColumnIndexAtX(e.getX());
int mc = scrollableTable
.convertColumnIndexToModel(vc);
customSorter.sort(mc);
fixedTable.repaint();
scrollableTable.repaint();
}
};
scrollableHdr.addMouseListener(scrollableListener);
} else if (customSorter != null) {
// If the listener is null, no action is performed by
removeMouseListener().
fixedHdr.removeMouseListener(fixedListener);
scrollableHdr.removeMouseListener(scrollableListener);
customSorter.sort();
}
}
/* ==================================================================== */
/**Creates and initializes the divided table.
*
* @param dm The TableModel.
* @param sorter The sort decorator for this table.
*/
private void initDividedTable(TableModel dm, AbstractSortDecorator
sorter) {
// Try to set sorter between model and view.
if (sorter != null) {
if (log.isInfoEnabled()) {
log.info("Creating a divided table with sorter '" +
sorter.toString() + "'");
}
customSorter = sorter;
fixedTable = new JTable(customSorter);
scrollableTable = new JTable(customSorter);
setMouseListenerToHeader(false);
} else {
if (log.isInfoEnabled()) {
log.info("Creating a divided table without sorter");
}
fixedTable = new JTable(dm);
scrollableTable = new JTable(dm);
}
// Reordering not allowed, because wanted columns can be substituted
with
// unwanted ones in the fixed table with this option set to true.
fixedTable.getTableHeader().setReorderingAllowed(false);
fixedTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
scrollableTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}
/* ==================================================================== */
/**Removes the columns said to be fix from the scrollableTable
TableColumnModel,
* sets the column width of fixedTable-columns to fixed size and
* sets the viewport size of fixedTable to the width of the fixed columns.
*/
private void removeFixedColsFromScrollableTable() {
TableColumnModel tcm = scrollableTable.getColumnModel();
// columnMargin necessary for displaying the grid line.
Dimension dim = new
Dimension(fixedTable.getColumnModel().getColumnMargin(),0);
for(int i = 0;i < fixedColumns; i++) {
dim.width += tcm.getColumn(i).getPreferredWidth();
fixedTable.getColumnModel().getColumn(i).setResizable(false);
// always delete the first column because columns in tcm are reordered
// after deletion
tcm.removeColumn(tcm.getColumn(0));
}
fixedTable.setPreferredScrollableViewportSize(dim);
}
/* ==================================================================== */
/**Creates the scrollPane for scrollableTable and setting its upper
* left corner view to fixedTable. Finally the scrollpane is installed
* on the provided container.
*
* @param contentPane The container the tables should get installed on.
*/
private void putTablesOnContainer(Container contentPane) {
scrollPane = new JScrollPane(scrollableTable);
scrollPane.setRowHeaderView(fixedTable);
scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER,
fixedTable.getTableHeader());
//with this line everything is ok:
contentPane.add(scrollPane);
}
/* ==================================================================== */
/**Allows only the selection of one row and synchronizes the selection
* in both tables. Both tables should be represented to the user as one.
* Therefore the selection model of the tables must be synchronized.
*/
private void synchronizeSelection() {
fixedTable
.getSelectionModel()
.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
int selRowIndex;
selRowIndex = fixedTable.getSelectedRow();
// only one row can be selected
scrollableTable.setRowSelectionInterval(selRowIndex, selRowIndex);
fixedTable.setRowSelectionInterval(selRowIndex, selRowIndex);
}
});
scrollableTable
.getSelectionModel()
.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
int selRowIndex;
selRowIndex = scrollableTable.getSelectedRow();
// only one row can be selected
fixedTable.setRowSelectionInterval(selRowIndex, selRowIndex);
scrollableTable.setRowSelectionInterval(selRowIndex, selRowIndex);
}
});
}
/* ==================================================================== */
/* (non-Javadoc)
* @see java.awt.Component#getPreferredSize()
*/
public Dimension getPreferredSize() {
return scrollPane.getPreferredSize();
}
/* ==================================================================== */
/* (non-Javadoc)
* @see javax.swing.JComponent#getMaximumSize()
*/
public Dimension getMaximumSize() {
return scrollPane.getMaximumSize();
}
/* ==================================================================== */
/* (non-Javadoc)
* @see javax.swing.JComponent#getMinimumSize()
*/
public Dimension getMinimumSize() {
return scrollPane.getMinimumSize();
}
/* ==================================================================== */
/* (non-Javadoc)
* @see javax.swing.JComponent#setMaximumSize(java.awt.Dimension)
*/
public void setMaximumSize(Dimension maximumSize) {
scrollPane.setMaximumSize(maximumSize);
}
/* ==================================================================== */
/* (non-Javadoc)
* @see javax.swing.JComponent#setMinimumSize(java.awt.Dimension)
*/
public void setMinimumSize(Dimension minimumSize) {
scrollPane.setMinimumSize(minimumSize);
}
/* ==================================================================== */
/* (non-Javadoc)
* @see javax.swing.JComponent#setPreferredSize(java.awt.Dimension)
*/
public void setPreferredSize(Dimension preferredSize) {
scrollPane.setPreferredSize(preferredSize);
}
/* ==================================================================== */
/** The JTable with fixed columns shown on the left. Not horizontally
scrollable. */
private JTable fixedTable;
/** The JTable with horizontally scrollable columns. */
private JTable scrollableTable;
/** The JScrollPane the JTables are installed on. */
private JScrollPane scrollPane;
/** The sorter for this divided table. */
private AbstractSortDecorator customSorter = null;
/** Stores the number of fixed columns on the left. */
private int fixedColumns;
}
- 8
- Back To College Is Here!Big, Big Savings!
College '07. Live. Study. Save. Back To College is one of our largest
campaigns of the year! Help our customers find the essentials they
need for college living at unbeatable prices.
Most See!
Click: http://ashopper.net
Donot miss out!
- 8
- Servlet for Connection Pooling in NetBeans & builtin TomcatHi,
I installed Netbeans 4.0 a few days ago and so far pretty impressed by
it. Previously I was using Tomat 4.0, and I like the idea of embedded
Tomcat 5 that can be managed via the IDE. To get things started, I
followed the article here:
http://www.netbeans.org/kb/using-netbeans/40/dbconn.html
to get a connection pool configured in the included Tomcat 5 web
server. Everything in the example works great. However, I don't want
to use the taglibs, and would rather write servlets and beans to do
the task. I tried following the example listed here:
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html
however that doesn't work for me (I get foo -1 or something; basically
its not working).
So I was wondering if someone could kindly provide me a simple servlet
that works in the Netbeans IDE so I can simply extend on the tutorial
here: http://www.netbeans.org/kb/using-netbeans/40/dbconn.html and and
draw connection from the tomcat 5 connection pool having configured
everything perfectly in this tutorial. Basically do the same thing as:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<sql:query var="queryresults" dataSource="jdbc/poolDB">
SELECT * FROM t_emp ORDER BY upper(f_name)
</sql:query>
<table border=1>
<tr>
<th>First</th><th>Last</th>
</tr>
<c:forEach var="row" items="${queryresults.rows}">
<tr>
<td><c:out value="${row.f_name}" /></td>
<td><c:out value="${row.l_name}" /></td>
</tr>
</c:forEach>
</table>
but in a servlet rather than using the tag library.
Very much appreciated!
- 13
- Binary search Tree:HelpIs this implementation of a binary search tree correct ?
numbers from 0 to 14 arranged in a binary tree (binary search tree). Is
this correct ? (left node is less, right node is greater than the
current node)
7
6 8
5 9 2 12
4 10 3 11 1 13 0 14
- 14
- Anyone using Studio 4 with MSAccess as DBMS?Is anyone using the Studio4 (Community version, Windows NT) IDE for
building forms using an MS Access database to supply a JTable via
net.beans palette components (nBCachedRowSet or nJcdbRowSet)? (Using
the JDBC-ODCB bridge). I can succesfully connect and initialize
components--can see the tables and columns in the Runtime explorer
connection--but when I execute the form, all columns are blank.
Also, when GUI editing, if I try to set the TableModel using the
TableEditor tab and select the nBCachedRowSet component, I get the
following error: "Unable to fetch columns; SQL-server rejected
establishment of SQL-connection. PointBase." Why is it still looking
at Pointbase?
Here's how components are set:
connectionSource1
Database URL = jdbc:odbc:IM_EDITOR (this works with MSQuery, so ODBC
is good)
Driver = sun.jdbc.odbc.JdbcOdbcDriver (ok here)
nBCachedRowSet1
command = select * from IM (this also works in MSQuery)
Database URL = jdbc:odbc:IM_EDITOR
jTable1
selection Model = nBCachedRowSet1
Need more code?
I give up! I really want to use Access for the DBM due to other
issues, but I am running out of patience!
TIA
Frustrated...
Mark
- 16
- Resize JSplitPane ContanierHi all,
I want to resize the container which holds JSplitPane. The situation
is with right button pressed the container should be resized to the
size of left component of JSplitpane and with left button pressed
container should be expanded to the size of left component +
Jsplitpane + right component, unlike the default behaviour of
JSplitpane. How can i acheive this?
Thanks in advance.
Naveen.
- 16
- simple STRUTS appi want to realize a simple struts app for creation of polls, can you
help me with ideas or examples?
a very very simple app but with "area" containers...and a simple
graphical representetion of the results...
tnx
|
| Author |
Message |
gk

|
Posted: 2005-11-1 21:15:00 |
Top |
java-programmer, servlet and thread
i am connecting to a servlet. i am passing some values from JSP to
servlet. the servlet gets those values from JSP by
request.getParameter(). then the servlet creates Threads as much as
values gives to it.
if the servlet is given 3 values from the JSP, then it would create 3
threads to calculate.
if the servlet is given 10 values from the JSP, then it would create 10
threads to calculate.
each Thread would return results to the JSP.
PROBLEM :
=========
how does my JSP would get the results from the threads. JSP would
refresh in 5 secs interval and would display the latest threads result.
|
| |
|
| |
 |
gk

|
Posted: 2005-11-1 21:27:00 |
Top |
java-programmer >> servlet and thread
i tried to put a bean in the server-side so that each thread would pour
data into it. but how does JSP would access that bean ? i am
refreshing the JSP in every 5 seconds interval.
i tried bean with static methods. and accessed the bean in my JSP. but
that is producing concurrency problems. (Not all the results are
coming out).
i also tried to put the threads results into session . but that too
also not producing result.
how does my JSP would get the results from the threads ?
please suggest example code.
regards
|
| |
|
| |
 |
dnasmars

|
Posted: 2005-11-3 22:19:00 |
Top |
java-programmer >> servlet and thread
gk wrote:
> i tried to put a bean in the server-side so that each thread would pour
> data into it. but how does JSP would access that bean ? i am
> refreshing the JSP in every 5 seconds interval.
>
> i tried bean with static methods. and accessed the bean in my JSP. but
> that is producing concurrency problems. (Not all the results are
> coming out).
>
> i also tried to put the threads results into session . but that too
> also not producing result.
>
>
>
> how does my JSP would get the results from the threads ?
> please suggest example code.
> regards
>
hello,
how about trying to create an instance in the servlet
a sort of threadmanager this instance gets the parameters from
the jsp on one hand create thread instances that do the calculation.
when the thread finishes it returns the result to the threadmanager.
The instance of the threadmanager has to be session scope so that
the jsp each 5 sec can see the results in the threadmanager.
I hope this helps
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- starting a weblogic servlet?Hello,
I have written a basic servlet of the form
public final class MyServlet extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
super.init(config)
/* do other stuff */
}
}
My question is, what do I need to do so that the "init" method is
invoked upon servlet (i.e. Weblogic) startup? I'm using Weblogic 5.1
sp 12 on Sun Solaris.
Thanks for your help, - Dave
- 2
- ports/81272: JDK 1.5 port doesn't build.Synopsis: JDK 1.5 port doesn't build.
Responsible-Changed-From-To: freebsd-amd64->freebsd-java
Responsible-Changed-By: arved
Responsible-Changed-When: Fri Nov 25 16:57:03 GMT 2005
Responsible-Changed-Why:
Refile, this looks like a ports issue.
Assign to port maintainers
http://www.freebsd.org/cgi/query-pr.cgi?pr=81272
- 3
- API 1.5.0 DownloadHi all,
I am new to the Mac and am looking for a download of the
jdk 1.5.0 api. I cannot find a tarball or zip file on the
Sun site that I can download so I can use the reference when
I am offline.
Suggestions?
Thanks,
Bob
- 4
- McDonalds/RoundTable, design&farm (was: I'm still waiting for ...)> From: email***@***.com (Michael Sullivan)
> ... instead of looking for exactly and precisely the kind of work
> that you have done in the distant past, ...
You're displaying a serious misconception. I'm available for any legal
work where I'd be doing something actually useful so that it would be
worth paying me to do it. It's the employers who refuse to even
consider people who haven't done exactly the same kind of work before.
> Go work at McDonalds
I tried that, when I had less than one year work experience. The
manager at the McDonalds on El Monte near El Camino Real told me that
because I have a college degree he won't consider me for employment
because he'd waste two months training me and then I'd find a better
job elsewhere and he'd be out the expense of training. Later that year
I got a job at Round Table Pizza on University in Palo Alto, where a
ditzy redhead Mrs. Masinter wasn't watching where she was going and
collided with my car and then freaked out seeing the car parts strewn
on the pavement, apologizing, exchanging insurance info, then she drove
off before giving me a chance to inspect the damage and see that all
the damage was to *her* car, not mine. Anyway, Round Table fired me
because I suffer a learning disability, unable to memorize the prices
on the menu. A year or two later I was sitting at a terminal at the
A.I. lab doing my usual work for free, and occasionally running FINGER
to see who else was around, when I saw Larry Masinter logged in, so I
wwnt over and asked if he was in any way related to that ditzy driver,
and indeed that was his former wife. He showed me Lisp for the first
time, impressed me, and after Hans Moravec explained the REP loop to me
I was forever going strong with Lisp.
> or a factory
That's not a good idea. I have very poor muscle coordination, can't
write legibly, can't do sports at all, take ten times as long as anyone
else to do a simple mechanical task in metal/wood shop in school and
still the result is cruddy, need extra space on both sides of car when
I'm driving because I can't judge distance between car and parket cars,
break almost anything physical I try to work on, did I tell you about
the disaster when I tried to do work on my car (tune-up, and lubricate
the air-duct wire-in-sleeve control cables)?
> a lot more brainpower goes into defining the problems that explicitly
> than into the actual coding,
Much of my work at Stanford was like that. Unfortunately there's no way
to express that with buzzwords on a resume, so you're not aware of that
from reading my resumes.
> and once you've done that part -- Indians and Chinese can and will
I'd be glad to design the software, farm it out to I&C, then check what
comes back to make sure it does the job that was required. Do you know
any such software-design jobs available now? I've never seen any such
jobs advertised anywhere, ever in all the years since I started
programming.
- 5
- Returning value from deep recursionI have the following code
***********************************
/**
* Recurses through schema finding the first instance of the
element name
* @param schemaElement - current element being compared from
schema
* @param checkElement - element to be checked against i.e. the
node selected in the gui
* @return the element in schema which matches the checkElement
*/
private Element findElementNameMatch(Element schemaElement, Element
checkElement)
{
// Get list of children
List listOfChildren = schemaElement.getChildren();
// If element has children
if(listOfChildren.size() != 0)
{
// Recurse through all elements under this one
for(int x=0; x < listOfChildren.size(); x++)
{
// Get child element
Element childElement = (Element) listOfChildren.get(x);
if(childElement.getName() == checkElement.getName())
{
return(childElement);
}
findElementNameMatch(childElement,checkElement);
}
}
return(null);
}
***********************************
The method is trying to find an element in an xml document that matches
a given name.
Can anyone give me tips on how to go about returning a value from deep
recursion to the first recursion of that particular method, so it can
return that value to the method that called it.
And also quite importantly how to stop any recursions after a match has
been found. EG a target element is found and returned, but how can i
stop the recursion going on to check elements under this element.
So far i have only achieved the two by creating a global variable and
flag, the variable is initialised when the match is found, and flag is
set to true so no more recursions are done afterwards.
- 6
- question about compiling java with textpadHow do i set a classpath in the javac? its not paying attention to the
classpath I have set at the environment level. This is windows 2000.
I go to configure->preferences->tools->compile java
I see $file in the parameters. Not able to do this:
-classpath <path> $file
and i get the standard javac error where it lists the options.
- 7
- model to xmlHi,
We have "Objects" that relate to each other in a parent-child
relationship. Also these objects can have references to ther objects
that is not a parent. Let me give you all an example.
I have the following parent-child relationship between objects,
Object A=1
|
-------------
| |
Object B=1 Object C=1
|
-------------
| |
Object D=1 Object D=2
Note: The number is the identity when we have more than one object of
the same type.
"Object A=1" is parent to child "Object B=1".
We have the same relationship for "Object D=1". "Object A=1" is parent
to "Object B=1" which is parent to "Object D=1". The path to "Object
D=1" is "Object A=1,Object C=1,Object D=1".
Also "Object B=1" can have a reference to "Object D=2". The
"reference"-attribute in "Object B=1" has the following path,
"Object A=1,Object C=1,Object D=2"
My question is if there is a tool where I can graphically create my
model ( see my nice one !!!) and from that generate an xml file ( or
xmi).
Requirements:
* It is important that when I create "Object B=1" it must be possible
for "Object B=1" to know that it's parent is
"Object A=1". When the hirarchy grows the child at the end should know
the whole path to itself.
* It is also important that a reference to an Object D=2 is created as
"Object A=1,Object C=1,Object D=2"
Has anyone done something similar? Any open-source tools for this? All
ideas/questions are welcome.
BR
//Mikael
- 8
- java vs ircHi
Im at a crossroad as to how to implement a webchat. I have the option of
building a chat using a standard IRC server saving me the trouble of
implementing it myself, OR i can write the server myself in Java giving me
full customizability. I would tend to go with the latter approach however im
rather concerned about performance. By performance im thinking bandwidth and
server load. So my question is: is it possible to build a chat server in
Java that is
a) better or equal to an IRC server utilizing bandwidth, and
b) better or equal to an IRC servers server load?
Im thinking performance wise that IRC would be better, but im not sure
whether this is true so im asking if anyone can give me some input as to why
one solution would be better than the other.
Thanx
Mike
- 9
- Hibernate on delete cascadeI use Hibernate and I am not able to do cascade delete.
After I create a project I have:
select * from project;
uid | name | shortdescription
-----+------+-----------------
1 | nc | NC Web application
(1 row)
After I subscribe to the project I have:
select * from subscription;
uid | account | project | role
-----+---------+---------+------
1 | 1 | 1 | 1
(1 row)
When I delete the project with a simple session.delete
try {
session.delete(project);
session.flush();
} catch (HibernateException e) {...
the row is deleted in the table "project"
but the row stays in table "subscription". Only the column entry "project" is set to null.
select * from subscription;
uid | account | project | role
-----+---------+---------+------
1 | 1 | | 1
(1 row)
I want the row to be deleted, how do I do that?
My two tables one for Projects and one for Subscriptions
<hibernate-mapping>
<class name="org.cobra.persistence.Project" table="project">
<id name="id" column="uid" type="long">
<generator class="increment"/>
</id>
<property name="name">
<column name="name" sql-type="char(32)" not-null="true"/>
</property>
<property name="shortDescription">
<column name="shortDescription" sql-type="char(256)" not-null="true"/>
</property>
<set name="subscriptions" table="subscription" cascade="all-delete-orphan">
<key column="project"/>
<one-to-many class="org.cobra.persistence.Subscription"/>
</set>
<set name="subscriptionsRequested" table="subscriptionRequest" cascade="all-delete-orphan">
<key column="project"/>
<one-to-many class="org.cobra.persistence.SubscriptionRequest"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="org.cobra.persistence.Subscription" table="subscription">
<id name="id" column="uid" type="long">
<generator class="increment"/>
</id>
<many-to-one name="account" column="account" cascade="all" class="org.cobra.persistence.Account" />
<many-to-one name="project" column="project" cascade="all" class="org.cobra.persistence.Project" />
<many-to-one name="role" column="role" cascade="all" class="org.cobra.persistence.Role" />
</class>
</hibernate-mapping>
- 10
- [eclipse] export with referenced librariesHello,
I am trying to export a project in jar format so that I can run it on
different machines. . I got a NoClassDefFoundError exception because
it requires referenced libraries (in this case, it is the MINA). Would
anyone please tell me how to export with referenced libraries?
Thanks
-k
- 11
- 12
- a simple java timerJust wondering, has anyone here ever used java.swing.timer if so, have you
got any examples? i cant seem to find many on google :s
- 13
- Null pointer exception while trying to repaint the component that displays a buffered image when the component is scrolled using scroll barI am trying to repaint a component that displays a buffered image when
the component is scrolled. I get the following error:
[java] java.lang.NullPointerException: NullSD does not handle
this operation
[java] at sun.java2d.NullSurfaceData.getRaster(Unknown Source)
[java] at sun.java2d.loops.OpaqueCopyAnyToArgb.Blit(Unknown
Source)
[java] at sun.java2d.loops.GraphicsPrimitive.convertFrom(Unknown
Source)
[java] at sun.java2d.loops.MaskBlit$General.MaskBlit(Unknown
Source)
[java] at sun.java2d.loops.Blit$GeneralMaskBlit.Blit(Unknown
Source)
[java] at sun.java2d.pipe.AlphaPaintPipe.renderPathTile(Unknown
Source)
[java] at sun.java2d.pipe.SpanShapeRenderer
$Composite.renderBox(Unknown Source)
[java] at sun.java2d.pipe.SpanShapeRenderer.spanClipLoop(Unknown
Source)
[java] at sun.java2d.pipe.SpanShapeRenderer.renderSpans(Unknown
Source)
[java] at sun.java2d.pipe.SpanShapeRenderer.renderPath(Unknown
Source)
[java] at sun.java2d.pipe.SpanShapeRenderer.fill(Unknown Source)
[java] at sun.java2d.pipe.ValidatePipe.fill(Unknown Source)
[java] at sun.java2d.SunGraphics2D.fill(Unknown Source)
[java] at
i3dea.ditto.DocumentImageDisplay.paintZone(DocumentImageDisplay.java:
256)
[java] at
i3dea.ditto.DocumentImageDisplay.paintComponent(DocumentImageDisplay.java:
467)
[java] at javax.swing.JComponent.paint(Unknown Source)
[java] at javax.swing.JComponent.paintChildren(Unknown Source)
[java] at javax.swing.JComponent.paint(Unknown Source)
[java] at javax.swing.JViewport.paint(Unknown Source)
[java] at javax.swing.JComponent.paintChildren(Unknown Source)
[java] at javax.swing.JComponent.paint(Unknown Source)
[java] at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown
Source)
[java] at javax.swing.JComponent.paintDoubleBuffered(Unknown
Source)
[java] at javax.swing.JComponent._paintImmediately(Unknown
Source)
[java] at javax.swing.JComponent.paintImmediately(Unknown Source)
[java] at javax.swing.RepaintManager.paintDirtyRegions(Unknown
Source)
[java] at javax.swing.SystemEventQueueUtilities
$ComponentWorkRequest.run(Unknown Source)
[java] at java.awt.event.InvocationEvent.dispatch(Unknown Source)
[java] at java.awt.EventQueue.dispatchEvent(Unknown Source)
[java] at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
[java] at
java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
[java] at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
[java] at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
[java] at java.awt.EventDispatchThread.run(Unknown Source)
Thanks
Mangai
- 14
- Memory Leakage drawing Images from Stream - Minimum exampleOk folks
I posted this a number of times ago,but never posted a minimum code
example for people to look at.
I was trying to load and draw images from a Mjpeg-Stream, reading from
the stream in a different thread.
This is the thread where the images are read by:
public class Axis2420
{
private HttpURLConnection hurlconnection = null;
private DataInputStream datainstream = null;
private String serialNumber = null;
private boolean connected = false;
private Frame dummy = null;
private Image image = null;
private String MJpegStreamUrl = null;
Runnable decodingThread = null;
public void SetURL(String url)
{
MJpegStreamUrl = url;
}
public boolean Connect()
{
if(MJpegStreamUrl == null)
{
System.out.println("Error: Empty Camera URL String");
return false;
}
try
{
URL streamurl = new URL(MJpegStreamUrl);
hurlconnection = (HttpURLConnection)streamurl.openConnection();
hurlconnection.setReadTimeout(10000);
//hurlconnection.setUseCaches(false);
InputStream instream = hurlconnection.getInputStream();
connected = true;
BufferedInputStream bis = new BufferedInputStream(instream);
datainstream = new DataInputStream(bis);
} catch(IOException e)
{
System.out.println("Fehler");
try
{
hurlconnection.disconnect();
Thread.sleep(60);
}
catch(InterruptedException ie)
{
hurlconnection.disconnect();
Connect();
}
catch(Exception ex)
{return false; }
System.out.println(e.getMessage());
return false;
}
return true;
}
//run method of the reading thread
public void run()
{
//test if still connected
if(!connected)
return;
try
{
//decode stream
if(connected)
{
Image i = null;
//ImageIO.setUseCache(false);
long before,after;
while(!Thread.currentThread().isInterrupted())
{
i = null;
String header;
int k = 0;
do
{
header = datainstream.readLine();
//System.out.println("Zeile: " +header);
}
while(++k < 3);
int j = (new Integer(header.substring("Content-Length:
".length()))).intValue();
datainstream.readByte();
datainstream.readByte();
// datainstream.readLine();
imageJPG = new byte[j];
datainstream.readFully(imageJPG, 0, j);
byte tail[] = new byte[4];
datainstream.readFully(tail,0,4);
i =
Toolkit.getDefaultToolkit().createImage(imageJPG,0,imageJPG.length);
image = i;
i = null;
fireChange(); //calls the stateChanged() method in
the class 'MainProgram' below
image = null;
i = null;
Thread.currentThread().sleep(10);
}
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
try {
datainstream.close();
} catch(Exception ex)
{
ex.printStackTrace();
}
}
}
//for the listening objects so they can fetch the latest image
public Image getLatestImage()
{
return image;
}
<....>
}
Once a new image has arrived, the fireChange() method calls this method
on the MainProgram class:
class MainProgram
extends JFrame
implements Runnable,ChangeListener
{
public static String WINDOW_TITLE = "BINO GESTENERKENNUNG";
public static int WINDOW_WIDTH = 640;
public static int WINDOW_HEIGHT = 480;
public static final int CAMERA_LEFT = 0;
public static final int CAMERA_RIGHT = 1;
//public static final String leftCameraURL =
"http://192.168.1.51/axis-cgi/mjpg/video.cgi?resolution=704x576&compression=25&clock=0&date=1&fps=10";
//public static final String rightCameraURL =
"http://192.168.1.51/axis-cgi/mjpg/video.cgi?resolution=704x576&compression=25&clock=0&date=1&fps=10";
public static final String leftCameraURL =
"http://192.168.1.51/axis-cgi/mjpg/video.cgi?resolution=352x288&compression=70&date=1&fps=5";
public static final String rightCameraURL =
"http://192.168.1.51/axis-cgi/mjpg/video.cgi?resolution=352x288&compression=100&date=1&fps=5";
Image currentLeftImage;
Image currentRightImage;
Graphics leftImageGraphics;
Graphics rightImageGraphics;
Graphics leftCameraGraphics;
Graphics rightCameraGraphics;
byte[] currentLeftImageJPG;
byte[] currentRightImageJPG;
BufferedImage testImage;
Axis2420 leftCamera = null;
Axis2420 rightCamera = null;
CameraCanvas leftCameraCanvas = null;
CameraCanvas rightCameraCanvas = null;
Runnable drawThread = null;
boolean readyToDraw = false;
boolean newImage = false;
long frameRateLeft = 0,frameRateRight = 0;
long frameTimesLeft[],frameTimesRight[];
//vPointerDetector leftImagePointer;
//vPointerDetector rightImagePointer;
vPointerDetector imagePointer;
boolean updateLeftImage,updateRightImage;
<.....lots of meaningless stuff.......>
public void stateChanged(ChangeEvent e)
{
currentRightImage = rightCamera.getLatestImage();
rightCameraCanvas.SetUpdate(true); //otherwise paintComponent()
of the JCanvas won't draw the image
rightCameraCanvas.SetImage(currentRightImage);
rightCameraCanvas.repaint();
currentRightImage = null;
currentRightImageJPG = null;
}
}
}
} //end of MainProgram class
Basically, all the stateChange method does is getting the image from the
image-reading thread ('rightCamera' of type Axis2420) after
rightCamera called fireChange(). The image is passed to an object of the
class CameraCanvas which derieves from JCanvas. After that, we cast
repaint() on the CameraCanvas (rightCameraCanvas.repaint() ).
This is the CameraCanvas that is responsible for drawing:
public class CameraCanvas extends JPanel
{
private Image image = null;
boolean drawNext = false;
boolean readyForNext;
public void paintComponent(Graphics g)
{
if(drawNext == true)
{
readyForNext =
g.drawImage(image,0,0,getSize().width,getSize().height,this);
//image.flush();
image = null;
//g.dispose();
//imageBuffered.flush();
drawNext = false;
}
}
//indicates that there is a new image
public void SetUpdate(boolean up)
{
drawNext = up;
}
//passes a new image to the Canvas
public void SetImage(Image i)
{
image = i;
}
}
The program draws the stream correctly and is smooth like butter.
However, there is a HUGE memory leak somewhere that raises the memory
usage by about 40MBytes per second. If I remove the call to
readyForNext = g.drawImage(image,0,0,getSize().width,getSize().height,this);
in the CameraCanvas thread, the leak will go down to about 40 kbyte /
second. If I leave it in and post a System.gc() call afterwards, the
leak will also go down.
I think that I'm somewhat polling the AWTEvent thread which lots of
copies of images waiting to be drawn. Also using
Toolkit.getDefaultToolkit().createImage(imageJPG,0,imageJPG.length);
spawns abouth 4 ImageFetcher threads which I think are the reason for
the small memory leak.
Now the question: What can I do about it?
It seems that the garbage collection isn't called after drawing an image
and casting it manually via System.gc() slows everything down a lot.
Using ImageIO.read)() instead of the Toolkit seems to remove the small
leak, but not the big one for drawing. And it tends to be slower since
it's blocking and keeping the Axis2420 thread from reading from the stream.
My thesis is due soon, so pleease have a look at it again.!!
Thanks in advance!!!
- 15
- IndexOf for whitespaceWhat if you wanted the indexOf either a space or a \n whichever came
first. Have you a slick way to code that?
Pedestrian possibilities include:
1. pair of indexOfs , take minimum ignoring <0s.
2. Write a loop that uses charAt
3. write a regex
Is there a slick way to handle it?
--
Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com
|
|
|