How can i improve this function?i need your help....

Hi guys,
i'm a pratical question for you.
I've developed a jas application that reads a txt file and convert it
into an array of byte,fro putting it into a blob field of a db mysql.
With big file i go in heap size memory!
I want to improve my function that makes it,but i'm a bit
inexpert...can you help me?
I have a file so made...
Each line has the same number of value,but i know this number only when
i read the file
string1 string2 string3................
stringx double double......(ever double)
stringy double double......(ever double)
and other lines equals to them from the second.
Only the first line has only strings.
I have read this file using a string array to read the first line and
an arraylist of "Riga" object to read the others lines.....i've used a
vector to store partial data from lines reading and at the end i've
created an array of byte in which i copy the vector.
Can you help me improving my code?
The file has about 50000 rows......so i go in heap memory size...
i know my code isn't too optimized.....can you help me?Please,i'm a
newbie,help me with code if possible...
When i encode the objects i've created into an array of byte i use a
whitespace to separe different value and a ; to separe different lines.
I've done it because in a second moment i've to read the array of byte.
Thanks...this is my code
public class MyBean {
        private UploadedFile myFile;
        private ArrayList rows = new ArrayList();
    private List lines = new ArrayList();
    public MyBean(){
    public List getLines(){
        return lines;
    public void setLines(List lines){
        this.lines=lines;
public boolean insRighe(Riga nuovo){
           return rows.add(nuovo);
    public UploadedFile getMyFile() {
        return myFile;
    public void setMyFile(UploadedFile myFile) {
        this.myFile = myFile;
    public ArrayList getRows() {
                return rows;
        public void setRows(ArrayList rows) {
                this.rows = rows;
    public String carica() throws IOException {
        Riga r;
        Double val[];
        Head h;
        int col=0;
        int row=0;
        byte middlerow=' ';
        byte endrow=';';
        byte[] data=null;
        Vector temp=new Vector();
        int numberOfNumericColumns=0;
        String geneid=null;
        String g=null;
        String[]intest=null;
        BufferedReader br = new BufferedReader(new
InputStreamReader(myFile.getInputStream()));
                String line = null;
        while ((line = br.readLine()) != null) {
                line = line.replace (',', '.');
                StringTokenizer st = new StringTokenizer(line);
                numberOfNumericColumns = (st.countTokens()-1);
                col=(numberOfNumericColumns+1);
            //se siamo nella prima riga(contatore segna 0)
                if(row==0){
                        intest=new String[col];
                        int j=0;
                        while(st.hasMoreTokens()){
                                intest[j]=(st.nextToken().trim());
                                j++;
                        h=new Head(intest);//crei l'oggetto head
                        String []qa=h.getHvalues();
                        String asd="";
                    for(int i=0;i<=qa.length-1;i++){
                        asd=asd.concat(qa[i]+" ");
                    System.out.println("head "+asd);//stampo contenuto
dell' head
                    row=1;
                }//fine if
                else
                        Double[] values=new Double[numberOfNumericColumns];
                    int z=0;
                    geneid=st.nextToken();
                    while (st.hasMoreTokens()) {
                        String app=st.nextToken();
                        values[z]=Double.valueOf(app);
                        z++;
                    r=new Riga(geneid,values); //crei l'oggetto riga
                    System.out.println("riga");
                    System.out.println(r.getgeneid());
                    values=r.getvalues();
                    for(int e=0;e<values.length;e++){
                        System.out.println(values[e]);
                    insRighe(r); //aggiungi
                row++;
                int i = 0;
                while (i < intest.length) {
                        byte[] bytesnew = intest.getBytes();
// temp.addAll(bytesnew);
// memorizza in byte un elemento del vettore alla volta
for (byte b : bytesnew)
temp.add(new Byte(b)); // provare Byte
// temp.addElement(intest[i].getBytes());
temp.addElement(Byte.valueOf(middlerow));
i++;
temp.addElement(Byte.valueOf(endrow));
System.out.println("Intestazione convertita in byte");
for (int l = 0; l < rows.size(); l++) {
r = (Riga) rows.get(l);
g = r.getgeneid();
// temp.addElement(g.getBytes());
byte[] byte2 = g.getBytes();
for (byte c : byte2)
temp.add(new Byte(c));
temp.addElement(Byte.valueOf(middlerow));
val = r.getvalues();
byte[] tempByte1;
for (int e = 0; e <= val.length - 1; e++) {
// Returns a string representation of the double argument.
tempByte1 = Double.toString(val[e]).getBytes();
for (int j = 0; j < tempByte1.length; j++) {
temp.addElement(Byte.valueOf(tempByte1[j]));
temp.addElement(Byte.valueOf(middlerow));
temp.addElement(Byte.valueOf(endrow));
data = new byte[temp.size()];
for (int t = 0; t < temp.size(); t++) {
data[t] = (((Byte) temp.elementAt(t)).byteValue());
return data;
public class Riga{
     private String geneid=null;
     private Double[] values=null;
     public Riga(String idGene,Double[] x ) {
this.geneid=idGene;
this.values=x;
     public String getgeneid(){
          return this.geneid;
     public void setgeneid(String idGene){
          this.geneid=idGene;
     public Double[] getvalues(){
          return this.values;
     public void setvalues(Double[] x){
          this.values=x;
Message was edited by:
giubat

Maybe I didn't understand you, but why are you putting a file with 50000 rows as one single BLOB into a DB? Don't you think it's time for a new table?

Similar Messages

  • How can i improve this query.

    Hi guys i am beginner , just wanted to know some info , how can i improve this query ..
    select *
    from tableA A, viewB B,
    where A.key = B.key
    and a.criteria1 = '111'
    and a.criteria2 = some_funtion(a.key)
    one more thing should function should be on left side of equal sign.
    will a join make it better or something else is needed more than that .

    952936 wrote:
    Hi guys i am beginner , just wanted to know some info , how can i improve this query ..
    select *
    from tableA A, viewB B,
    where A.key = B.key
    and a.criteria1 = '111'
    and a.criteria2 = some_funtion(a.key)
    one more thing should function should be on left side of equal sign.
    will a join make it better or something else is needed more than that .If you are a beginner try to learn the ANSI Syntax. This will help you a lot to write better queries.
    Your select would look like this in ANSI.
    select *
    from tableA A
    JOIN viewB B ON A.key = B.key
    WHERE a.criteria1 = '111'
    and a.criteria2 = some_function(a.key);The good thing here is that this separates the typical joining part of the select from the typical filter criteria.
    The other syntax very often let you forget one join. Just because there are so many tables and so many filters, that you just don't notice correctly anymore what was join and what not.
    If you notice that the number of column is not what you expect, you can easiely modify the query and compare the results.
    example A
    Remove View B from the query (temporarily comment it out).
    select *
    from tableA A
    --JOIN viewB B ON A.key = B.key
    WHERE a.criteria1 = '111'
    and a.criteria2 = some_funtion(a.key)
    example B
    You notice, that values from A are missing. Maybe because there is no matching key in ViewB? Then change the join to an outer join.
    select *
    from tableA A
    LEFT OUTER JOIN viewB B ON A.key = B.key
    WHERE a.criteria1 = '111'
    and a.criteria2 = some_funtion(a.key)(The outer keyword is optional, left join would be enough).

  • Hello there,  there is a rare window that keeps popping up every time i start Logic.  I'd like to send a screenshot... anyway, it's a "tempo" window with strange layout about midi effects and so,.... is it normal?  How can i improve this?  Thanks.

    hello there,  there is a rare window that keeps popping up every time i start Logic.  It's a "tempo" window with strange layout about midi effects and so,.... is it normal?  How can i improve this?  Thanks.

    Hmm, that's some sort of MIDI Arpeggiator setup in your environment. Strange that you don't know it, this has to be custom-installed, it is not part of the standard setup.
    You can do two things about it:
    1.unlock your current screenset (shift-L), then close the (Bass Driver) window, then relock the screenset (shift-L). Next time you open up this project you won't see the Bass Driver, but it is still in the project.
    2. You can remove the whole page: open the Environment (cmd-8), then go to the dropdown menu arrow top left of the Environment window and select the Bass Driver layer. If it is selected, dropdown again and choose Delete. Now Save your project under a different name (Save As...), so that you still keep the Bass Driver setup in the original project. If you don't need to keep it, you can simply Save.

  • Finally upgraded to Lions OSX. The Mac screen is now hard to view as everything has a grey tinge. How can I improve this? Tried

    Finally took the plungs and upgraded to Lion OSx so that I could access icloud. Everything worked ok but I now find it difficult to view the screen. Everything has a grey tinge and with my poor eyesight it's really frustrating. Zooming in is ok but I would really like more contrast. What was wrong with crisp white and deep black? Have tried to change the profiles in System Preferences but it's confusing to follow and after 3 attempts I still don't like any of the profiles. My photos all have an unnatural colour now. How can I improve this and bring everything back to 'normal'? Whose 'bright' (?) idea was it to make everyting grey and why???

    Thanks. Very helpful. It's now less of a strain for me. But the fonts are still too pale. I really need to be able to read words that are black. In Mail, the sender and headings are dark enough, but the content is still too light for me to read without straining. Any other suggestions?

  • I am shooting with a Nikon D60 on Fine Format and unable to print larger than 11x14.  I have been able to print larger pictures.  I am told iPhoto reduces the size of the file when uploaded. Is this true? If so how can I change this?  I need 16x20's

    I am shooting with a Nikon D60 on Fine Format and unable to print larger than 11x14.  I have been able to print larger pictures.  I am told iPhoto reduces the size of the file when uploaded. Is this true? If so how can I change this?  I need 16x20's

    I am shooting with a Nikon D60 on Fine Format and unable to print larger than 11x14.  I have been able to print larger pictures.  I am told iPhoto reduces the size of the file when uploaded. Is this true? If so how can I change this?  I need 16x20's

  • When I try to back up my iPad to the computer it gives me a message saying it can't sync and cannot back up because there is not enough room in the iTunes library. How can I fix this? I need to back up the iPad content so I can restore it to a new 1

    when I try to back up my iPad to the computer it gives me a message saying it can't sync and there is not enough room in iTunes library. How can I fix this? I need to back up iPad content to restore on a new one

    juliefrombaton rouge wrote:
    when I try to back up my iPad to the computer it gives me a message saying it can't sync and there is not enough room in iTunes library.
    Pretty sure it doesn’t say there is not enough room in iTunes library because it is not backed up to the iTunes library.
    What is the exact message?

  • How can i use this  function module

    Hai
    How can i use this function module /SAPHT/SALES_ORDER_READ, already apply the some parameters in this function module, but it shows the error , please tell me, how to declare the parameters in this function module ,
    thanks
    neelima

    Hi
    For a particular sales order,you have to pass the order number and the item number in the sales order.
    It will display the rest of the values which u can capture them using internal tables.
    Regards,
    Vishwa.

  • Today I updated the OX Maverisk. It turns out that the three finger gesture in the finder( go back and forward) is disabled. How can I get this function back? I love it so much!!!

    Today I updated the OX Maverisk. It turns out that the three finger gesture in the finder( go back and forward) is disabled. How can I get this function back? I love it so much!

    Try System Preferences/Trackpad/More Gestures.

  • How can I get this function to fire off last?

    In the following code, there are two buttons on the stage- "button1" and "button2". 
    I want to get the buttons to change frames and THEN have the "playerChange" function fire off.
    Currently, the "playerChange" function fires first. Moving the function  either renders the code inoperable or
    returns error messages.
    function buttonChange (e:MouseEvent)
    {if    
                    (e.target.currentFrame == "frame1" )
             if (e.target==button1) (playerChange)
                     (e.target.gotoAndStop(player.currentFrame + 1)) 
               else{player.gotoAndStop(player.currentFrame)
              if (e.target==button2)  (playerChange) 
                    (e.target.gotoAndStop(player.currentFrame + 1))
              else{player2.gotoAndStop(player2.currentFrame)
    button1.addEventListener(MouseEvent.CLICK,buttonChange );
    button2.addEventListener(MouseEvent.CLICK,buttonChange);
    Note:this is an abridged version of the code. The code I'm actually using uses 20 buttons and about 8 conditionals for each button, so e.target is more convenient than writing a command for each button.

A: How can I get this function to fire off last?

the code is very hard to understand
it's badly formatted
{}'s don't match
you aren't calling a playerChange function
this is my guess at something that might work for you
function buttonChange (e:MouseEvent)
          if(e.target.currentFrame == "frame1" )
                    if (e.target == button1)
                              e.target.gotoAndStop(player.currentFrame + 1);
                              playerChange();
                    else
                              player.gotoAndStop(player.currentFrame);
                              if (e.target == button2)
                                        e.target.gotoAndStop(player.currentFrame + 1);
                                        playerChange();
                              else
                                        player2.gotoAndStop(player2.currentFrame)
button1.addEventListener(MouseEvent.CLICK,buttonChange );
button2.addEventListener(MouseEvent.CLICK, buttonChange);

the code is very hard to understand
it's badly formatted
{}'s don't match
you aren't calling a playerChange function
this is my guess at something that might work for you
function buttonChange (e:MouseEvent)
          if(e.target.currentFrame == "frame1" )
                    if (e.target == button1)
                              e.target.gotoAndStop(player.currentFrame + 1);
                              playerChange();
                    else
                              player.gotoAndStop(player.currentFrame);
                              if (e.target == button2)
                                        e.target.gotoAndStop(player.currentFrame + 1);
                                        playerChange();
                              else
                                        player2.gotoAndStop(player2.currentFrame)
button1.addEventListener(MouseEvent.CLICK,buttonChange );
button2.addEventListener(MouseEvent.CLICK, buttonChange);

  • Hi. There is a ghost search bar on my iMac screen which flashes constantly, even during start up and shut down. How can i make this go away? Please help. x

    Hi There is a ghost search bar on my iMac that flashes continually, even during start up and shut down. How can i make this go away? Please help. x

    Please read this whole message before doing anything.
    This procedure is a test, not a solution. Don’t be disappointed when you find that nothing has changed after you complete it.
    Step 1
    The purpose of this step is to determine whether the problem is localized to your user account.
    Enable guest logins* and log in as Guest. Don't use the Safari-only “Guest User” login created by “Find My Mac.”
    While logged in as Guest, you won’t have access to any of your documents or settings. Applications will behave as if you were running them for the first time. Don’t be alarmed by this behavior; it’s normal. If you need any passwords or other personal data in order to complete the test, memorize, print, or write them down before you begin.
    Test while logged in as Guest. Same problem?
    After testing, log out of the guest account and, in your own account, disable it if you wish. Any files you created in the guest account will be deleted automatically when you log out of it.
    *Note: If you’ve activated “Find My Mac” or FileVault, then you can’t enable the Guest account. The “Guest User” login created by “Find My Mac” is not the same. Create a new account in which to test, and delete it, including its home folder, after testing.
    Step 2
    The purpose of this step is to determine whether the problem is caused by third-party system modifications that load automatically at startup or login, by a peripheral device, by a font conflict, or by corruption of the file system or of certain system caches.
    Please take this step regardless of the results of Step 1.
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards, if applicable. Start up in safe mode and log in to the account with the problem. You must hold down the shift key twice: once when you turn on the computer, and again when you log in.
    Note: If FileVault is enabled, or if a firmware password is set, or if the startup volume is a software RAID, you can’t do this. Ask for further instructions.
    Safe mode is much slower to start up and run than normal, with limited graphics performance, and some things won’t work at all, including sound output and Wi-Fi on certain models. The next normal startup may also be somewhat slow.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    Test while in safe mode. Same problem?
    After testing, restart as usual (not in safe mode) and verify that you still have the problem. Post the results of Steps 1 and 2.

  • Since updating my iPhone 4 to iOS5, my music stats (play count, last played, etc.) no long sync to iTunes. How can I fix this? Thanks for the help.

    Since updating my iPhone 4 to iOS5, my music stats (play count, last played, etc.) no long sync to iTunes. How can I fix this? Thanks for the help.

    If you have any podcasts in your iTunes library you should see a Podcasts sync setting tab to the right when you connect your phone and click on its name on the left sidebar (see image below).  On this tab check to sync podcasts and sync your phone.

  • Hi, I have an iPhone 1 that is blocked (because of wrong passwords) and isn't recognized by iTunes. How do I fix this? Thanks for your help!

    Hi, I have an iPhone 1 that is blocked (because of wrong passwords) and isn't recognized by iTunes. How do I fix this? Thanks for your help!
    By the way I'm using a MacMini and all operating systems are up to date including iTunes.

    First try a Reset  ( No Data will be Lost )
    Press and hold the Sleep/Wake button and the Home button at the same time for at least Ten seconds... (But can take Longer)... until the Apple logo appears. Release the Buttons
    If no joy... Try a Restore...
    1: Connect the device to Your computer and open iTunes.
    2: If the device appears in iTunes, select and click Restore on the Summary pane.
    Restoring  >  http://support.apple.com/kb/HT1414
    3: If the device doesn't appear in iTunes, try using the Steps in this article to force the device into Recovery Mode.
    Make sure you have the Latest Version of iTunes (v11.1.5) Installed on your computer
    iTunes free download from www.itunes.com/download

  • How can I improve this?

    It's basically to add lots of tasks that should execute after a certain amount of time and execute them efficiently. How can I improve it? I've already thought of making the Events loop able.
    package eventmanager;
    import java.util.Collections;
    import java.util.LinkedList;
    import java.util.List;
    * Handles the processing of timed event
    * very efficiently.
    * @author Colby
    public class EventEngine {
        public static void main(String[] args) {
            Event e1 = new Event(1000) {
                @Override
                public void execute() {
                    System.out.println("Executed 1000ms");
            Event e2 = new Event(2000) {
                @Override
                public void execute() {
                    System.out.println("Executed 2000ms");
            EventEngine engine = new EventEngine();
            engine.add(e1);
            engine.add(e2);
        public static abstract class Event implements Comparable {
            public Event(long timeUntilExecute) {
                this.timeCreated = System.currentTimeMillis();
                this.timeUntilExecution = timeUntilExecute;
            @Override
            public int compareTo(Object o) {
                if (!(o instanceof Event)) {
                    throw new IllegalArgumentException("Input Object must inherit from eventmanager.Event");
                Event e = (Event) o;
                long thisLeft = getTimeUntilExecution();
                long otherLeft = e.getTimeUntilExecution();
                return thisLeft < otherLeft ? -1 : otherLeft < thisLeft ? 1 : 0;
            public abstract void execute();
            public boolean timeToExecute() {
                return getTimeUntilExecution() < 1;
            public long getTimeCreated() {
                return timeCreated;
            public long getTimeUntilExecution() {
                return timeUntilExecution - (System.currentTimeMillis() - timeCreated);
            private long timeCreated;
            private long timeUntilExecution;
        public EventEngine() {
            this.events = new LinkedList<Event>();
            Runnable task = new Runnable() {
                @Override
                public void run() {
                    while (true) {
                        try {
                            cycle();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
            Thread t = new Thread(task);
            t.setName("Event Manager");
            t.start();
        private void cycle() throws InterruptedException {
            synchronized (this) {
                if (events.isEmpty()) {
                    wait();
                } else {
                    Collections.sort(events);
                    Event e = events.get(0);
                    if (e.timeToExecute()) {
                        e.execute();
                        events.remove(0);
                    } else {
                        wait(e.getTimeUntilExecution());
        public void add(Event e) {
            synchronized (this) {
                events.add(e);
                notify();
        private List<Event> events;
    }Edited by: Jadz_Core on Jan 21, 2010 4:05 PM

    Jadz_Core wrote:
    Melanie_Green wrote:
    Jadz_Core wrote:
    Nobody has any criticism :O
    return thisLeft < otherLeft ? -1 : otherLeft < thisLeft ? 1 : 0;MelBecause it's against conventions or can it be done better?The code is barely readable.
    if(thisLeft < otherLeft) {
      return -1;
    else if(otherLeft < thisLeft) {
      return 1;
    else {
      return 0;
    }Is slightly more readable yet not quite adequate. In fact this looks something similar to hmmmm....
    Long thisLeft = getTimeUntilExecution();
    Long otherLeft = e.getTimeUntilExecution();
    return thisLeft.compareTo(otherLeft);Ahhhhhhhhh
    Mel

  • How can I accomplish this function that control a server application on jav

    Now I write a server application,and want write a control shell to operate it,like start,stop,restart and so on.
    just like the apache server shell and Tomcat 5.0 server shell,but mine shell just add the system configure panel.
    I need your help,Thank u very much!

    just make your server to listen to some specific
    command either in the same port or different port.I don't know what u say,can u give me an example?or very specific introduce.
    how to listen to some specific command in the same port or different port.

  • How can i improve this code ?

    DATA: t_bkpf TYPE bkpf.
    DATA: t_bseg type bseg_t.
    DATA: wa_bseg like line of t_bseg.
    select * from bkpf into t_bkpf where document type ='KZ' and bldat in s_bldat.
    select single * from bseg into wa_bseg where belnr = t_bkpf-belnr.
    append wa_bseg to t_bseg.
    endselect.
    loop at t_bseg into wa_bseg.
      at new belnr.
         if wa_bseg-koart EQ 'K'.
            // pick vendor wrbtr
         else
           // pick other line item's wrbtr
         endif.
      endat.
    endloop.
    i am guessing my select statements arnt efficient performance wise, secondly in the loop when i use  'at new belnr' it aint showing my any values  whereas i get all the vendors(KOART EQ 'K') when i dont use 'at new belnr' .
    why is this so and how can i make the code efficient ?
    Thanks..
    Shehryar

    Hi,
    1.Dont read all the fields from the table unless it is required in your program.
    This will tremendously improve your performance.
    2.Make use of the key fields of the table wherever possible
    In your scenario you could use the fields BUKRS,BELNR,GJAHR of the table BKPF in the WHERE Clause rather than
    other fields.This will improve your performance a lot..
    3.As BSEG is a cluster table it will cause performance problem in most cases.So try to read
    the required fields from it rather than reading all the fields.Again Make use of the key fields in the WHERE Clause
    here too to improve the performance..
    4.Remove SELECT..ENDSELECT and replace it with FOR ALL ENTRIES to improve the performance.
    Cheers,
    Abdul Hakim
    Mark all useful answers..

  • Maybe you are looking for