Improving speed in a java program

i have a fairly simple content blocking program, it accesses a database, this puts a user profile in an array to compare it against a web page classification.
The database used is Oracle and I'm connecting with a JDBC thin client. The web page classifications are currently been loaded from a text file and inserted into an 2D array.
My problem, the program is really slow.. i need to speed it up, any idea's or suggestion, area's to research.

The code is a bit long but any thoughts would be appreciated
import java.sql.*;
import java.io.*;
import java.util.*;
* This is a small program that will retreive the user profile data from the
* database and checked it against random page classifiers created. This will
* supply the number of pages blocked or accepted.
* @author
public class SetUpDatabase extends Object {
private Connection conn; //A database connection
int userId = -1; //The user id of the user who requested the internet content.
//User Profile Variables used to store data from the user profile database
boolean userProfileLocation = false; //The value of the location filter option in the user profile database.
boolean userProfileKey =false; //The value of the Keyword filter option in the user profile database.
boolean userProfileSkin =false; //The value of the Skin filter option in the user profile database.
boolean userProfileIcra = false; //The value of the ICRA filter option in the user profile database.
boolean userProfileRsaci = false; //The value of the RSACi filter option in the user profile database.
boolean userIcra[] = new boolean [46]; //An array to store the Icra profile retrieved from the user profile database.
int userRsaci[] = new int[6]; //An array to store the RSACi profile retrieved from the user profile database
// 2D array variables used to store data retreived from the Files
int incomingFileUser[][] = new int[100000][6]; //This 2d array is used to store the user profile extracted from a text file.
int incomingFileIcra[][] = new int[100000][46]; //This 2d array is used to store the ICRA rating extracted from a text file.
int incomingFileRsaci[][] = new int [100000][4]; //This 2d array is used to store the RSACi rating extracted from a text file.
// Array variables to hold converted incoming web page classifiers
boolean incomingPageClassifiers[] = new boolean[5]; //An array to store the internet content classifiers
boolean incomingIcraRating[] = new boolean [48]; //An array to store the incoming ICRA rating
int incomingRsaciRating[] = new int[5]; //An array to store the incoming RSACi rating
// Counters
//The amount of pages and records that have been processed
int numBlocked = 0; //The number of pages not blocked.
int numAllowed = 0; //The number of pages blocked.
// Icra Filter Counters
int icraCalled = 0; //The number of pages blocked with ICRA labels
int icraAccepted = 0; //The number of pages blocked with ICRA labels
int icraBlocked = 0; //The number of pages blocked with ICRA labels
//Rsaci Filter Counters
int rsaciCalled = 0; //To keep count of the total number of times the icra filter is called.
int rsaciAccepted = 0; //The number of pages blocked with RSACi labels
int rsaciBlocked=0; //The number of pages blocked with RSACi labels
//Misc
Random random = new Random(); //An object to create random numbers
boolean blocked = false; //A switch to indicate if the page should be blocked.
int numPages = 0; //A variable to hold the number of pages that have been put in the text box
* Constructor
* This connects to the database. It has methods that create random users, icra
* and rsaci profile. It also access the user profile database to collect user profile
* data.
* @param numPages, this is an integer value from the User Interface specifying
* the number of pages that are to be created.
public SetUpDatabase(int incomingNumPages, String option) {
numPages = (incomingNumPages-1);
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException c){
System.out.println("Problem:Could not load database drivers");
if (option == "Random"){
try {
for(int i= 0;i <= numPages;i++) {
userId = (int)((random.nextFloat()) * numPages);
GetUserData();
CreateRandomClassifiers();
RandomFilter();
} catch (SQLException h) {
System.out.println ("Problem with the Random Option.");
}else{
try {
int row = 0;
int col = 0;
int classifierIndex = 0;
GetFileUser(numPages);
GetFileIcra(numPages);
GetFileRsaci(numPages);
for(row= 0;row <= numPages;row++) {
userId = (int)(incomingFileUser[row][0]);
classifierIndex = 0;
for(col=1;col<=5;col++){
incomingPageClassifiers[classifierIndex]= ConvertBoolean(incomingFileUser[row][col]);
classifierIndex++;
col=0;
for(col=0;col<=45;col++){
incomingIcraRating[col] = ConvertBoolean(incomingFileIcra[row][col]);
col=0;
for (col=0;col<=3;col++){
incomingRsaciRating[col] = incomingFileRsaci[row][col];
col=0;
String dburl="jdbc:oracle:thin:@192.168.0.1:1521:up";
//Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(dburl,"gary","happygary");
// conn = DriverManager.getConnection("jdbc:oracle:oci8:@UP","gary","happygary");
GetUserData();
FileFilter();
conn.close();
//System.out.println("row= "+row+" the user ="+userId + "numALlowed =" + numAllowed);
} catch (SQLException h) {
System.out.println ("Method calling problem");
* Method - This goes to the database and gets the user profile information,
* it uses the random user id from CreateRandomUser method.
void GetUserData () throws SQLException {
try {
Statement s = conn.createStatement();
String state = ("SELECT * FROM user_profile WHERE user_id=" + userId);
ResultSet rset = s.executeQuery (state);
while (rset.next()) {
int temp[] = new int[5];
int col=6;
for (int i = 0;i<=4;i++){
temp= rset.getInt(col);
col++;
userProfileLocation =ConvertBoolean(temp[0]);
userProfileKey = ConvertBoolean(temp[1]);
userProfileSkin = ConvertBoolean(temp[2]);
userProfileIcra = ConvertBoolean(temp[3]);
userProfileRsaci = ConvertBoolean(temp[4]);
rset.close(); // close the resultSet
s.close(); // Close the statement
} catch (SQLException g) {
System.out.println ("did not work");
* Method - This creates a random user profile
void CreateRandomClassifiers() {
float randomNumber = 0;
randomNumber = random.nextFloat(); // This creates a random number between 0.0 - 1.0, this is for the user_id By multiplying the random number by 1000 we can create a random number between 0 and 1000
userId = ((int)(randomNumber *1000));
for (int i =0;i<4;i++){
incomingPageClassifiers[i] = CreateRandomBoolean(10.5);
* Method - Filter
* This compares the incoming internet classification with the retrieved database information.
void RandomFilter () throws SQLException {
try {
if ((userProfileLocation ==true && incomingPageClassifiers[0]==true)||(userProfileKey==true && incomingPageClassifiers[1]==true)||(userProfileSkin==true && incomingPageClassifiers[2]==true)){
numBlocked ++;
} else if ((incomingPageClassifiers[3]==true && userProfileIcra == true)) {
GetUserIcra();
CreateRandomIcra();
IcraFilter();
} else if ((incomingPageClassifiers[4]==true && userProfileRsaci == true)){
GetUserRsaci();
CreateRandomRsaci();
RsaciFilter();
} else {
numAllowed ++;
}catch (SQLException l){
System.out.println ("filter problem");
* Method - Filter
* This compares the incoming internet classification with the retrieved database information.
void FileFilter () throws SQLException {
try {
if ((userProfileLocation == true) && (incomingPageClassifiers[0]==true)){
blocked = true;
} else if ((userProfileKey == true) && (incomingPageClassifiers[1]==true)){
blocked = true;
}else if ((userProfileSkin==true) && (incomingPageClassifiers[2]==true)){
blocked = true;
}else if ((userProfileIcra == true) && (incomingPageClassifiers[3]== true)) {
GetUserIcra();
IcraFilter();
} else if ((userProfileRsaci == true) && (incomingPageClassifiers[4]==true)){
GetUserRsaci();
RsaciFilter();
} else {
blocked = false;
if (blocked == true ){
numBlocked++;
blocked = false;
} else {
numAllowed++;
}catch (SQLException l){
System.out.println ("Filter problem");
* Method - GetUserICra
* This accesses the User Profile database and gets the ICRA profile details
void GetUserIcra() throws SQLException {
try {
Statement s = conn.createStatement();
String state = ("SELECT * FROM Icra WHERE user_id=" + userId);
ResultSet rset = s.executeQuery (state);
ResultSetMetaData rsmd = rset.getMetaData();// get the number of columns
int numCols = rsmd.getColumnCount ();
int icraIndex=0;
while (rset.next()) {
for (int colNum =2;colNum<=46;colNum++){
userIcra[icraIndex] = rset.getBoolean (colNum);
icraIndex++;
rset.close(); // Close the resultSet
s.close(); // Close the statement
} catch (SQLException g) {
System.out.println ("Problem with Obtaining ICRA profile from database");
* Method - GetUserRSACi
* This gets the Rsaci profile data from the User Profile Database
void GetUserRsaci() throws SQLException {
try {
Statement s = conn.createStatement();
String state = ("SELECT * FROM Rsaci WHERE user_id=" + userId);
ResultSet rset = s.executeQuery (state);
ResultSetMetaData rsmd = rset.getMetaData(); // get the number of columns
int numCols = rsmd.getColumnCount ();
int rsaciIndex=0;
while (rset.next()) {
for (int colNum =2;colNum<=5;colNum++){
userRsaci[rsaciIndex] = rset.getInt (colNum);
rsaciIndex++;
rset.close(); // close the resultSet
s.close(); // Close the statement
} catch (SQLException g) {
System.out.println ("Problem with Rsaci");
* Method - CreateRandomIcra
* This creates a random icra classification
* @return It stores a boolean value in the pageIcra array variable
void CreateRandomIcra () {
for (int i = 2; i<=45;i++) {
incomingIcraRating[i]=CreateRandomBoolean(1.1);
* Method - CreateRandomRsaci
* This creates the integer values between 0-9 for a rsaci profile.
* @return It stores the random Rsaci profile in a pageRsaci variable
void CreateRandomRsaci () {
for (int i = 2; i<=5;i++) {
incomingRsaciRating[i]=CreateRandomInteger(10);
* Method - IcraFilter
* The Icra Filter
void IcraFilter() {
icraCalled++;
for (int i = 0;i<=45;i++) {
if ((userIcra[i] == true) && (incomingIcraRating[i] == true)){
blocked = true;
if (blocked == true) {
icraBlocked++;
} else {
icraAccepted++;
* Method -RsaciFilter
* The Rsaci Filter
void RsaciFilter() {
rsaciCalled++;
for (int i = 0;i<=3;i++) {
if ((userRsaci[i] >= 1) && (incomingRsaciRating[i] <= userRsaci[i])){
blocked = true;
if (blocked == true) {
rsaciBlocked++;
} else {
rsaciAccepted++;
* Method -This creates a random boolean.
* @param - percentage of likelyhood that boolean is true
* @return - boolean value
boolean CreateRandomBoolean(double percentage) {
double indicator = (random.nextFloat())*100;
if (indicator <= percentage) {
return true;
} else {
return false;
* Method - CreateRandomInteger
* @return Creates a random integer between the value of 0-9.
private int CreateRandomInteger(int percentage){
int indicator = 0;
indicator = (int)((random.nextFloat())*100);
if (indicator <= percentage) {
return(int)((random.nextFloat())*10);
} else {
return 0;
void GetFileUser(int numPages){
// assuming doubles and assuming you know the number
// of rows is m and the number of columns is n...
int numRows = numPages;
String line = null;
StringTokenizer st = null;
int row = 0;
int column = 0;
try {
BufferedReader in = new BufferedReader(new FileReader("C:\\java\\user.txt"));
// assuming each line contains one row of n values
try{
while( (( line = in.readLine())!= null)&&(row <=numRows)){
st = new StringTokenizer(line, ", ");
while(st.hasMoreTokens()) {
try{
incomingFileUser[row][column] = new Double(st.nextToken()).intValue();
} catch(NumberFormatException nfe) {
incomingFileUser[row][column] = 0;
column++;
column=0;
row++;
}catch (IOException ioe){
System.out.println("File reading error");
} catch (FileNotFoundException e){
System.out.println("File Not Found");
void GetFileIcra(int numPages){
// assuming doubles and assuming you know the number
// of rows is m and the number of columns is n...
int numRows = numPages;
String line = null;
StringTokenizer st = null;
int row = 0;
int column = 0;
try {
BufferedReader in = new BufferedReader(new FileReader("C:\\java\\icra.txt"));
// assuming each line contains one row of n values
try{
while( (( line = in.readLine())!= null)&&(row <numRows)){
st = new StringTokenizer(line, ", ");
while(st.hasMoreTokens()) {
try{
incomingFileIcra[row][column] = new Double(st.nextToken()).intValue();
} catch(NumberFormatException nfe) {
incomingFileRsaci[row][column] = 0;
column++;
column=0;
row++;
}catch (IOException ioe){
System.out.println("file reading error");
} catch (FileNotFoundException e){
System.out.println("File Not Found");
void GetFileRsaci(int numPages){
// assuming doubles and assuming you know the number
// of rows is m and the number of columns is n...
int numRows = numPages;
String line = null;
StringTokenizer st = null;
int row = 0;
int column = 0;
try {
BufferedReader in = new BufferedReader(new FileReader("C:\\java\\rsaci.txt"));
// assuming each line contains one row of n values
try{
while( (( line = in.readLine())!= null)&&(row <numRows)){
st = new StringTokenizer(line, ", ");
while(st.hasMoreTokens()) {
try{
incomingFileRsaci[row][column] = new Integer(st.nextToken()).intValue();
} catch(NumberFormatException nfe) {
incomingFileRsaci[row][column] = 0;
column++;
column = 0;
row++;
}catch (IOException ioe){
System.out.println("file reading error");
} catch (FileNotFoundException e){
System.out.println("File Not Found");
boolean ConvertBoolean(int number) {
if (number == 1){
return true;
} else{
return false;
* Method - This opens the database connection
//accessor methods
public int GetNumberBlocked (){
return numBlocked;
public int GetNumberAllowed(){
return numAllowed;
public int GetIcraCalled(){
return icraCalled;
public int GetIcraAccepted(){
return icraAccepted;
public int GetIcraBlocked(){
return icraBlocked;
public int GetRsaciCalled(){
return rsaciCalled;
public int GetRsaciAccepted(){
return rsaciAccepted;
public int GetRsaciBlocked(){
return rsaciBlocked;

Similar Messages

  • Speed at which JAVA programs are executed

    While it is true that a typical JAVA program will execute slower than an equivalent program written in other languages such as C++.
    Is it because the compiled bytecodes (.class) have to be interpreted by the JVM?
    Thanks.

    yep, a .class is bytecode... the JVM interprets the bytecode "on the fly".
    The JVM's major task is to "interpolate" native operating system requests. That's why the JVM is platform specific.
    The bytecode to native interpretation takes a few clock ticks, so it's a might slower than native compiled code... but it's practically important to realise that this is not the big performance hit inherent in a "Virtual Machine"... the big (potential) performance loss is the overhead of "interpolating" every single O/S interface request... hence String BufferedReader.readLine() is light-years faster than char InputStream.read(), because .read() has to (1) interpret your request, (2) set the registers, (3) do an operating system interupt, (3) interpret the response... for EVERY SINGLE EENY WEENY CHARACTER... which in practice means you can't do an usable java port of directX... which is a shame really.
    But is does mean that you can (almost) write a webapp which is completely portable across platforms (with zero code change).
    horses....
    keith.
    Message was edited by:
    corlettk

  • How can speed up my java program ? native code compilation ?

    Hello everyone, I know that there are so many post related to compiling to native code.
    My situation is that I wrote a little program that gets executed upto 50 times per second. This program basically gets a set of parameters and after validating them, they get inserted into a SQL Server 2000 table.
    I need this program to be faster ?
    I was thinking of writting this again on c++ but I don't know how to do it and I must do it myself.
    Thanks for you time,
    Sincerly Fabian.

    When we get 1500 traps in one second, the CPU
    utilization gets overloaded and the server crashes.C++ will be slightly faster if you are truly CPU-bound, assembly will be faster still. However, at some point nothing will be able to keep up. So the real question is whether Java provides enough development-level support and cross-platform capability to justify its slightly slower performance.
    Some things to think about:
    1) Are you running multiple threads to process incoming messages? You might be better off buffering the messages and processing them on a single or pooled thread. If the message traffic is truly bursty, and you don't need real-time response (which is illusory anyway), this should reduce your load.
    2) To echo another poster, are you really invoking a program for each message? Can you run that operation within the same JVM? There's a significant cost for each program start, as well as for context switches.
    3) You mentioned that you're writing to a database. Can you batch the writes? Individual writes result in more network round-trips, as well as more context switches.

  • I ran the program to improve speed and crashing and lost my norton tool bar and vault login

    I ran the program to improve speed and crashing and lost my norton tool bar and vault with all my log ins. I am sure it is still here some place but can not find it.

    Hi flkeen, Did you try to uninstall that program which you install to improve speed ..see if that works after un install that program....and restore the firefox after uninstalling that program.
    see link here for reset firefox https://support.mozilla.org/en-US/kb/reset-preferences-fix-problems?esab=a&s=restore+firefox&r=1&as=s#w_solution-1-reset-firefox-to-its-default-state

  • Should I upgrade to Lion from 10.6.8 to improve stability of Java program i am running?

    I have a Java program problem, it's unstable and losing connection and freezing. Will an upgrade to Lion from 10.6.8 help?
    thanks

    they don't claim it but it is. I have never had a problem with the 2008 macbook, just the desktop. Narrowed it down to this after trying everything else speaking with Scottrade, Oracle and Apple.
    I tried to downgrade but got lost at the utilitoes terminal part. any easier way? Apple wont help me downgrade through my care program and I have no idea.
    Thanks

  • Can I use a C/C++ xml parser in my java program?

    Hi,
    How can I use a C/C++ xml parser in my java program?
    Elvis.

    You would still need to convert the XML data structure into a Java data structure to import it into Java.
    Don't assume you need C++ to do anything. I woudl write it in Java first, then profile the application to see where the bottle necks are and then optimise them
    Don't optimise code unless you have proof it needs to be optimised.
    If you want to improve the speed of reading XML, try XMLbooster

  • Java stored procedure vs. PL-SQL vs. external java program

    Hi,
    I'm using a stored procedure for running a query and a few consequent updates. Currently I'm using Java stored procedure for that, which was my choice for simplicity on one hand, and running with the DB on the other.
    In my tests, strangely enough it came out that running as java stored procedure was 3-4 times slower than running as a java program outside the database. I don't know how to explain this, and I wonder if switching to PL/SQL will improve the performance of the code.
    Any experiences? recommendations?
    Thanks,
    Dawg

    In my tests, strangely enough it came out that running as java stored procedure was 3-4 times slower than running as a java program outside the database. I don't know how to explain this, and I wonder if switching to PL/SQL will improve the performance of the code.This isn't strange at all. See: Oracle's JVM (Aurora) is an independent Java Virtual Machine implementation, in accordance to specification. It implements all necessary parts of it (I think so). When you use an external JVM (I assume it's Sun's HotSpot JVM) you use completely different product. It is implemented in different way, it has many different code parts.
    One of the biggest differences between Oracle's JVM and Sun's JVM is [Just-in-Time compiler|http://en.wikipedia.org/wiki/Just-in-time_compilation]. Oracle has implemented it only in the 11g version of database, i.e. 2 years ago, while Sun performed it back in 2000 and continues to improve it for the last 9 years. That would explain obvious differences between Java program inside and outside the DB: they are executed in absolutely different worlds. Diffs could be up to 10x times or more - that's not unusual.
    If you are on 10g and want to compare performance of stored Java procedure vs external program, then you might use additional command-line instruction for external program to disable JIT:
    -XintPS. I wouldn't use Java for your task - that's a total overkill. Use simple SP instead.

  • Will upgrading ram improve speed in Mac and windows (VMware fusion)?

    I Am using VMware fusion for music production and that program requires a lot of workspace. I have a MacBook Pro 4gb ram and when I turn VMware on it goes to 2 gb ram in Mac and 2 gb ram in windows. My Mac speed is normal when VMware fusion is turned off but when I turn it on my Mac is very slow. Will upgrading ram improve speed in mac and also in windows (windows is also very slow)
    Btw my english isn't very good 

    Adding RAM only makes it possible to run more programs concurrently.  It doesn't speed up the computer nor make games run faster.  What it can do is prevent the system from having to use disk-based VM when it runs out of RAM because you are trying to run too many applications concurrently or using applications that are extremely RAM hungry.  It will improve the performance of applications that run mostly in RAM or when loading programs.
    In your case it will most likely help. You should plan on at least 8 GBs or more, depending upon what your model supports.

  • To invoke a java Program from non-java Clients

    I need to develop a program in java which will be invoked using some non java client. For example: for the time being my java application will be invoked by tandem. Also, a huge volume of transactions can be expected to come in and these need to be processed at high speed(response time of 5 seconds or so). Any suggestions ?

    By Tandem..I mean a non-java client...
    We need to look at possible architectures for implementing the payment module of the an application. We can think of the payment module as a Java process that does the following � 1. validate the card and some other stuff....
    The payment module should be able to support non java clients...
    Take the case when a customer swipes a card at a store.... Another process (call it the router) determines if the transaction info needs to be sent to my java program... If yes , the router invokes my payment module. The router can vary from store to store ... So my Payment module will be invoked by non java clients... As part of deciding on the architecture we need to decide on the protocol used for communication � http/tcp/iiop etc.
    Also, we need to decide on the various options for implementing the payment module.... It can be webservices, EJB Session Beans etc... But the key point is ,.....performance.... A huge volume of transactions can be expected to come in and these need to be processed at high speed(response time of 5 seconds or so).

  • How to implement a print screen through a java program rather than a keyboa

    help needed urgently to make a college project.
    have to capture whatsoever is on the client screen
    and sent it to to a server program where it will be made visible on a frame or panel.
    this is to be done without the client ever knowing it.
    so needed to implement a printscreen command using java code and put it in a program(also how to make
    the .class file containing this code run in the background all the time since the client comp starts till it is shut down without the client ever knowing it)
    e mail: [email protected]

    <pre>
    hartmut
    i need help.
    i've recently started using the web to learn more about java.your reply was very discouraging.
    the proff. just wants a decent project.
    but i want to make this project to improve my java networking skills.
    if you can help , please tell me how to implement a printscreen through a java program rather than a keyboard.
    I'll be very grateful to you if you can help me in this regard, but please dont send a dissapointing response like the previous one.
    mail: [email protected]
    </pre>

  • Improve speed for deleting process

    Hi all,
    I am writing a housekeeping program to check on the table ZTP_ADA for the invalid date format.
    If invalid date format record is found, then delete the record (delete those records which are erroneous). The table is having a huge number of records, might reach around millions of records.
    To make it short, the program will does this: -
    1) Delete records which are in invalid date format.
    My question is, how to improve the speed for the current program, which might takes more than half an hour for deleting records.
    Any suggestions or ideas are greatly appreaciated.
    Million thanks.
    DATA: lv_datum  TYPE sy-datum,
          lv_commit TYPE c,
          lv_excep  TYPE REF TO CX_ROOT.
    DATA: ITAB_ADA TYPE SORTED TABLE OF ZTP_ADA WITH NON-UNIQUE KEY TABLE LINE,
          WA_ADA LIKE LINE OF ITAB_ADA.
    SELECT * from ZTP_ADA
      INTO TABLE ITAB_ADA.
    LOOP AT ITAB_ADA INTO WA_ADA.
      lv_datum = WA_ADA-DATUM.
      CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
      EXPORTING
      date = lv_datum
      EXCEPTIONS
      plausibility_check_failed = 1
      OTHERS = 2.
      IF sy-subrc <> 0.
      DELETE FROM ztp_ada
        WHERE DATUM = WA_ADA-DATUM.
      ENDIF.
    ENDLOOP.

    Did u try to remove the sorted table option from the internal table.Sorted table needs to be used only in case the records are sorted. And it adds to the processing if it is not sorted properly.
    Make the internal table Standard table
    Also I find that you are actually deleting the entries from the database table.
    Delete the entries from the internal table which are having the wrong date format.
    Then delete all the entries from the data base table and update the internal table into the database. This will be faster and you will hit the data base only thrice in the whole program.
    This will fasten the process.
    I would have used the following code below
    DATA: lv_datum  TYPE sy-datum,
          lv_commit TYPE c,
          lv_excep  TYPE REF TO CX_ROOT.
    DATA: ITAB_ADA TYPE STANDARD TABLE OF ZTP_ADA,
          WA_ADA LIKE LINE OF ITAB_ADA.
    SELECT * from ZTP_ADA
      INTO TABLE ITAB_ADA.
    DELETE * FROM ZTP_ADA
    INTO TABLE ITAB_ADA.
    LOOP AT ITAB_ADA INTO WA_ADA.
      lv_datum = WA_ADA-DATUM.
      CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
      EXPORTING
      date = lv_datum
      EXCEPTIONS
      plausibility_check_failed = 1
      OTHERS = 2.
      IF sy-subrc  0.
      DELETE ITAB_ADA WHERE DATUM = LV_DATUM.
      ENDIF.
    ENDLOOP.
    INSERT ZTP_ADA FROM TABLE ITAB_ADA.
    Hope this helps.
    Regards,
    Hari

  • Fast loading Java program

    The book "Core Java, Volume I" by Horstmann and Cornell gives a hint for writing a Java program that loads quickly. They suggest that explicit references to other classes be eliminated from the main class, then use Class.forName to force the loading of the other classes.
    I would like to see if the loading of other classes can be done on demand. Here is the schetch of my idea for instantiating and calling a method.
    Class myClassObj = Class.forName("MyClass");
    Object myObj = myClassObj.newInstance();
    Constructor myConstr = myClassObj.getConstructor(new Class[] {String});
    myConstr.invoke??
    Method myMethod = myClassObj.getMethod("myMethod",new Class[]{String,int});
    myMethod.invoke(myObj,new Obj []{"Julie",23});
    Here are my questions:
    1. I can use myClassObj.getConstructor to get a specific constructor but how would I invoke it? Does newInstance call a constructor already?
    2. How would Invoke a static method?
    3. If this approach is feasible, would you recomend it?
    Thanks for your help.

    1. I can use myClassObj.getConstructor to get a
    specific constructor but how would I invoke it? Does
    newInstance call a constructor already?The newInstance of Class calls the constructor with no arguments. To create an object using a Constructor instance, use its newInstance method.
    2. How would Invoke a static method?The API documentation for the invoke() method of Method tells you that. It says "If the underlying method is static, then the specified obj argument is ignored. It may be null."
    3. If this approach is feasible, would you recomend
    it?Almost certainly not. If you simply replace explicit references to the class by calls to Class.forName(), you are still going to be loading the same classes at the same time. So I don't see how this would speed up loading. And I definitely wouldn't recommend putting all that reflection code in your program. First of all, it's slower, so you could negate whatever benefits you might have got at loading time, and second, it makes your program hard to write, difficult to maintain, and subject to run-time errors because you don't allow the compiler to check method names and signatures.
    But if time to load the program is of much higher importance than any of those other considerations, then give it a try.

  • I need to improve speed....

    Gents,
    I'm having an Java app which is logging "messages" into another another window(emulating the console with some clever functionality). In this window I'm using a JTextArea for displaying messages, and it seems that repainting this JTextArea is a bottleneck for performance... Do some of you have experience about the topic and some ideas of how to improve speed ?
    Maybe use a simpler component than JTextArea, but I need copy&paste functionality in there ?
    Cheers,
    Preben

    I feel the need...the need for speed!Sounds like my last 2 weeks! We developed filters for the database to clean some data and projected comletion of the run with filtes was 135 days for the first set (not good, especially since 17 different algorithms had to be applied). We've steadily brought it down, so now a run takes about 16 minutes.
    speed... Speed... SPEED... I feel the need!

  • Error while running a Java Program

    Can anyone help me,
    I am getting the following error while running a Java program, Below is the exception thrown, please help.
    java.nio.BufferOverflowException
    at java.nio.Buffer.nextPutIndex(Buffer.java:425)
    at java.nio.DirectByteBuffer.putChar(DirectByteBuffer.java:463)
    at org.jetel.data.StringDataField.serialize(StringDataField.java:295)
    at org.jetel.data.DataRecord.serialize(DataRecord.java:283)
    at org.jetel.graph.DirectEdge.writeRecord(DirectEdge.java:216)
    at org.jetel.graph.Edge.writeRecord(Edge.java:288)
    at com.tcs.re.component.RESummer1.run(RESummer1.java:505)
    java.nio.BufferOverflowException
    at java.nio.Buffer.nextPutIndex(Buffer.java:425)
    at java.nio.DirectByteBuffer.putChar(DirectByteBuffer.java:463)
    at org.jetel.data.StringDataField.serialize(StringDataField.java:295)
    at org.jetel.data.DataRecord.serialize(DataRecord.java:283)
    at org.jetel.graph.DirectEdge.writeRecord(DirectEdge.java:216)
    at org.jetel.graph.Edge.writeRecord(Edge.java:288)
    at com.tcs.re.component.RECollectCont.run(RECollectCont.java:304)

    Ok, let's see. Write the following class:
    public class Grunt {
      public static void main(String[] args) {
        System.out.println("Hello Mars");
    }Save it as "C:\Grunt.java", compile by typing:
    javac c:\Grunt.javaRun by typing:
    java -classpath "C:\" GruntDoes it say "Hello Mars"? If yes, go back to your program and compare for differences (maybe you used the "package" statement?).
    Regards

  • Running a java program a set number of times

    This is a general question. Is it possible to make a java program run only 5 times for the sake of arguement.
    Basically I want to write a program that will give the user some flexibility when it will actually run another Java program, but I only want them to be able to say "not now' for a set number of times. When the last time comes the other program will launch. I was initially thinking of the Do Whilw loop, but this needs to work when the program is restarted.
    Program starts, it has 5 times it will run before it does something else(doesn't really matter now I think). User takes option "Not Now" and the program ends, but warns the user this will run 4 more times before you will need to do something.
    This process will repeat until the user takes the option "Ok install now" or the time limit expires and the install occurs anyway. Can someone point me in the right direction.

    ok I see so it's like one those programs that you download for free on the internet and they give you a set amount times to use it before you have to pay for it. but in this case when the number of times you use it equals 5 (or when the user clicks ok) a different java app will open automatically.
    My first thought would be to Write a Serialized object to disk using objectOutputStream that stores the number of times the application has been opened. and each time the program runs it checks for the serialized object and then you can do something like what I posted before. of course if were worried about security the user could always look for the object and erase it, if so then I guess we would have to come up with another plan of attack
    Hope this helps

Maybe you are looking for