Reusing StringBuffer in discussions to create less garbage string

My application connects to our server via SocketConnection. The server sends a set of strings formatting that contains the last trade funds. So whenever a new trade occurs, the server will send an individual Stock Quote of this profession. Through an InputStream, I am able to read this information and place each character in a StringBuffer which is referenced by the Threads. By char3 -based I am able to determine a set of stock quote/information.

CAR1 - data separate char3 - signifies the end of a stock market quote/information

format of stock quote of sample sent by our server:

stock_quote_name (tank 1) some_data (char1) some_data (char1) (char3)

My application then parses the stock quote to compare some data formats and she how she will look like when displayed in the screen. When trades are gradually (slow) the app works perfectly. However...

Problem: what trades coming too fast and almost at the same time, my app is not able to process the information sent efficiently. The StringBuffer has its content combined with the following trade. Which means that two stock market information in a StringBuffer.

field should be: Stock_quote_name some_data some_data

sample of what's going on: Stock_quote_name some_dataStock_quote_name some_data some_data some_data

Here is my code for this part:

while (-1 != (data = is.read()))
{
    sb.append((char)data);
    while(3 != (data = is.read()))
    {
         sb.append((char)data);    }

    UiApplication.getUiApplication().invokeLater(new Runnable()
    {
        public void run()
        {
            try
            {
             /*
              *while data from input stream is not equal to -1 or 3 (end of quote set) continue to read.
              *
              */
              Synchronized(UiApplication.getEventLock(               {
               SetStringBuffer(sb);                   DisplayStringBuffer();                            RefreshStringBuffer();
          }
             } catch (Exception e)
             {
                 System.out.println("Error in setting stringbuffer: " + e.toString());
             }
        }
    });
}
public synchronized void DisplayStringBuffer()
{
   try
   {
       //parse the stock information
   }
   catch(Exception ex)
   {
       System.out.println("error in DisplayStringBuffer(): " + ex.toString());
   }
}
public synchronized void SetStringBuffer(StringBuffer dataBuffer)
{
    this.sb =dataBuffer;
    System.out.println(sb);
}
public synchronized void RefreshStringBuffer()
{
    this.sb.delete(0, this.sb.length());
}

From what I see, when trades happen very quickly, the StringBuffer is not refreshed immediately and always has the contents of the previous trade, when I try to put new data.

My Question is: How to synchronize the re-use of the stringbuffer and add new characters without next information being appended to the first content and blockages

Then, you need not to use invokeLater. You're emptying the buffer on the floor area, and if the executable is not executed immediately before of you put more data, you will see the problem you are experiencing.

What it looks like you want is a pattern of traditional consumer/producer here, that should work fine.

Tags: BlackBerry Developers

Similar Questions

  • Error Photoshop CC while opening jpeg files created less than 24 hours ago "could not complete your request because it is not the right kind of document.

    I am under photoshop cc and a sudden am this message cannot open jpg files. And so, I used photoshop to create less than 24 hours. Any suggestions?

    Thanks for sharing files.

    Looks very good load on my end.

    Suggest you to reinstall Camera Raw from this link and then check: https://helpx.adobe.com/x-productkb/multi/camera-raw-plug-in-installer.html

  • If we can reuse the Configuration element already created in the model of the ATO... ?

    Dear all,

    Please note that we started using the model workflow ATO for order management.

    Its been noticed that every time when the configuration is done, it creates a configuration item, which will be there in the master of the order of the day.

    In our business case, we can have different configurations each sales order. In this case,.

    Is there a way that we can reuse the same once its created configuration... ?

    Please update... ?

    Thanks in advance...

    Corresponding CTO can be lit. With running, if the same options are selected on a second sales order, then the CTO process will use the existing element rather than create a new item.

    There are several options to enable the corresponding feature. There are profiles that turn it on to a site... or corresponding level can be configured to work only for specific models (via an attribute of the element).

    For more information about the corresponding feature of CTO, see Configure Oracle Guide ordering process to:

    http://download.Oracle.com/docs/CD/B34956_01/current/Acrobat/120ctopg.PDF

    Thank you
    Jason

  • Error #1056: Could not create property 0 String.

    I found similar to this subject positions but could not find my situation.

    I have 2 tables, one is filled earlier in the program by entries of the user in the following format:

    VideoArray [0]: Nothing

    VideoArray [1]: [object]

    VideoArray [1] [0]: String (this string is registration by the user in a text field)

    VideoArray [1] [1]: String (this string is registration by the user in a text field)

    Then, it follows the pattern of user input:

    [2]: object

    [2] [0]: string

    [2] [1]: string

    [3]

    [3] [0]

    [3] [1]

    ... Repeat for as long as the user enters data.

    I try to copy the data in another table by using a series of loops since I won't know how many sets of data from user input. I need not the object data in the new table. The new array (InfoArray) will be structured as follows:

    InfoArray [0]: String

    InfoArray [1]: number

    InfoArray [2]: Nothing

    InfoArray [2] [0]: VideoArray [1] [0]

    InfoArray [2] [1]: VideoArray [1] [1]

    InfoArray [3] [0]: VideoArray [2] [0]

    InfoArray [3] [1]: VideoArray [2] [1]

    .. Repeat until all the data is copied.

    I do this with the following:


    ArrayCount = VideoArray.length + QuestionArray.length + 2



    for (var i: int = 0; i < = ArrayCount; i ++)



    {




    If (i == 0)




    {





    InfoArray [i] = ModuleName;




    } else




    {





    If (I == 1)






    {







    InfoArray [i] = Number_Of_Videos;





    } else






    {







    If (I < = Number_Of_Videos + 2)






    {







    InfoArray [i] = [];






    for (var j: int = 0; j < = 1; j ++)






    {







    trace ("I =" + i);






    trace ("j =" + j);






    trace ("VideoArray [i-1] [j]:" + VideoArray [i-1] [j]);






    InfoArray [i] = ' video: '; "
    Line 272




    InfoArray [i] [j] is VideoArray [i-1] [j];.





    }





    } else






    {

    (don't know why he copied the code like this, I couldn't find a button "Insert code")

    When I run it, I get my tracks and the error:

    I have = 2

    j = 0

    VideoArray [i-1] [j]: v1

    ReferenceError: Error #1056: cannot create property 0 String.

    at BWSModuleGenerator_fla::MainTimeline/Compile_Info() [BWSModuleGenerator_fla. [MainTimeline: frame1:272]

    Ive never gotten this error before and im not sure what is wrong with my code.

    Thanks for any help.

    It's a little confusing trying to follow your data storage scheme and that could be a big part of the problem, but for two lines show you...

    InfoArray [i] = ' video: '; "

    InfoArray [i] [j] is VideoArray [i-1] [j];.

    If the first is a string, the second cannot be an element of a table if that is the intention.  It seems that the compiler considers to try to target a property from a string using the notation of support where the [j] at the end is interpreted as a property, not an index of an array.

  • Looping through a list to create a url string

    Hi all

    This should be easy for someone with a little experience, but for some reason I have problems with it.  I need to create a url string based on the results of the query.  The results of the query are essentially:

    agenda Prix
    125542.00
    238853.50
    125545.00
    885442.47

    I need to create a url like www.something.com/index.cfm string? item1 = 122554 & item1price = 2 & item2 = 23885 & item2price = 3.50 etc etc (I'm actually trying to create the channel and then add it to a url.)  The index must be included also, like item1, item2 but there will be a different result for each order number if that makes sense - this person bought 4 items but someone else could buy 2).

    Can someone give me a good way to do this?  I tried to loop through the query sort, but it does not work for me.  I also tried making a list but no dice.  It seems that it should be so simple.

    Thank you

    Red

    It seems that you overwrite rather than allow adding to your string variable.

    Take one resembles the quick example below.  Note that I have not tested this code.

    http://www.example.com/page.cfm? » >

  • How to create a substitution string

    Hello

    How do I create a chain of replacement so it can point to a url or the page.

    for example I want to place all my images in a page named www.page.com/images/

    So how can I create the replacement string so then I can just put the #APP_IMG #IMAGE_NAME.jpg to call it that.

    I tried to create a chain of substitution as this #APP_IMG # that points to www.page.com/images/, but its does not work.

    Any ideas?

    Ruben

    You cannot create chains of substitution of #SOMETHING #. However, you are on the right track. If you change the definition of application (where you can change the name or the analysis of schema), you will see a 20 ' Substitution static channels "that you can set. The key is how refer you to them. You must use the & STRING. syntax and don't FORGET not the trailing dot. In an application I'm working on, we have a chain called IMAGE_BASE. Currently, it is set on/myapp /. In my model, I reference images / javascript / js like this:

    &IMAGE_BASE.some_css.css
    

    When the page is rendered, the reference will look like this:

    /myapp/some_css.css
    

    Note that you can also set the value of this string of substitution of #WORKSPACE_IMAGES #, which is nice because you can choose where to deploy your images. I really need to blog about this a while...

    Tyler Muth
    http://tylermuth.WordPress.com
    [Oracle security application: development of secure database and Middleware environments | http://sn.im/aos.book]

  • When use REUSE/SET, no.-ARCHIVELOGS in create controlfile in HOT BACKUP?

    I am an Oracle DBA intern and I have the following queries. Good response with detailed explanations, I want to get my deleted concepts!

    T1 > > while a user managed hot backup, when we create a path for recovery (CREATE CONTROLFILE) control file when we use the control file created with the following options:
    * 1. REUSE / SET *.
    * 2. ARCHIVELOGS / NOARCHIVELOGS *.

    T2 > > in what scenarios re - create the control file while recovering the data from a hot backup files?

    Thanks a ton!
    Kind regards
    Blabla

    Specify REUSE to indicate that existing control files identified by CONTROL_FILES initialization parameter can be reused and overwritten.

    SET the DATABASE to change the name of the database.

  • How to reuse stringBuffer...

    I have this:

    StringBuffer sb = null;String value;
    
    Loop{
    value = g4ttu6n;
    sb = new StringBuffer(value);....Send(sb);}
    

    And I wondered: is there a way to do something like this:

    String value;
    StringBuffer sb = new StringBuffer(value);
    
    Loop
    {
       value = grfdt5tgr;
       Send(sb);
    }
    

    I don't know if it's possible...

    Thank you

    setLength (.) and append (...) seem to be the methods that you want to use, especially setLength (0) to delete it.

  • Creating huge garbage files.

    All of a sudden, SSDFEXXXX files appear on my hard drive, hundreds of them.  When I delete them they are replaced by xxxxxx.tmp files which I cannot remove.  Can someone tell me what is happening?

    Hello

    -Did you do changes on the computer before the show?

    This could be caused due to virus infected the computer.

    I suggest to download Microsoft Safety Scanner, then scan your computer for viruses and malware then check how it works.

    You can download Microsoft Safety Scanner from the link "scan to Microsoft Security.

    Note:  The Microsoft Safety Scanner ends 10 days after being downloaded. To restart a scan with the latest definitions of anti-malware, download and run the Microsoft Safety Scanner again. All data that are infected must be cleaned only by deleting all of the data, which means that there is a risk of data loss.

  • Eception java.lang.error trying to create format XML string

    I am trying to create XML documents without having to build everything manually whenever I want to do this.  I created a XMLFile class to create the document.  When I try to launch my app TestFoo, I get untrapped Exception java.lang.error.  I tried kxml2, using org.w3c.dom, java XML, banging my head against the wall as to why it will not work until I finally just rolled my own simple implementation.  I always get the error!  No details are provided.  There is no stack trace.  I use the emulator 9000 "BOLD" crossing os 4.6.0 eclipse 3.4.1

    Console:

    Starting TestFooStarted TestFoo(154)Exit TestFoo(154)ErrorNo detail messageTestFoo Document  0x171TestFoo XMLFile  0x381TestFoo TestFoo  0x297TestFoo TestFoo main 0x276
    

    TestFoo.java

    import net.rim.device.api.system.Application;
    
    public class TestFoo extends Application {
    
      public static void main(String[] args) {      TestFoo foo = new TestFoo();      foo.enterEventDispatcher();   }
    
      public TestFoo() {        XMLFile xml = new XMLFile("rootNode");        xml.addProperty("myprop", "some value");      System.out.println(xml.toFormattedXMLString());       System.exit(0);   }}
    

    XMLFile.java

    public class XMLFile {   Document document;    public XMLFile(String rootElement) {      document = new Document(rootElement); }
    
      public void addProperty(String pName, String pText) {     Element elm = new Element("property");        elm.addAttribute("name", pName);      elm.setTextContent(pText);        document.appendChild(elm);    }    public String toFormattedXMLString() {     return document.toFormattedXML();    }}
    

    Element.Java

    import java.util.Enumeration;import java.util.Hashtable;import java.util.Vector;
    
    public class Element {   private Vector children;  private String name;  private String textContent;   private Hashtable attributes;
    
      public Element(String name) {     this.children = new Vector();     this.attributes = new Hashtable();        this.name = name; } public void appendChild(Element child) {      this.children.addElement(child);  } public Vector getChildren() {     return children;  } public String getName() {     return name;  } public void setName(String name) {        this.name = name; } public String getTextContent() {      return textContent;   } public void setTextContent(String textContent) {      this.textContent = textContent;   } public Hashtable getAttributes() {        return attributes;    } public boolean hasChildren() {        return (this.children.size() > 0); } public int childrenCount() {      return this.children.size();  } public String getAttributeValue(String name) {        return this.attributes.get(name).toString();  } public void addAttribute(String key, String value) {      this.attributes.put(key, value);  } public void addAttribute(String key, int value) {     addAttribute(key,Integer.toString(value));    } public void addAttribute(String key, long value) {        addAttribute(key,Long.toString(value));   } public void addAttribute(String key, boolean value) {     addAttribute(key, String.valueOf(value)); } public boolean hasAttribute(String name) {        return this.attributes.containsKey(name); } public Element getChild(int position) {       return (Element) this.children.elementAt(position);   } public Enumeration getAttributeKeys() {       return this.attributes.keys();    }}
    

    Document.Java

    import java.util.Enumeration;
    
    public class Document { private static final char _gt = '>';   private static final char _lt = '<';   private static final char _eq = '=';  private static final char _dqt = '"'; private static final char _cl = '/';  private static final char _sp = ' ';  private static final char _tab = '\t';    private static final byte[] _nl = System.getProperty("line.separator").getBytes();
    
      private Element rootNode; private StringBuffer sb;
    
      public Document(String rootName) {        this.rootNode = new Element(rootName);    } public void appendChild(Element child) {      this.rootNode.appendChild(child); } public String toFormattedXML() {      sb = new StringBuffer();      format(this.rootNode,0);      return sb.toString(); }
    
      private void format(Element node, int depth) {        writeOpenTag(node, depth);        for (int i=0;i0;i--) {            sb.append(_tab);      } }    private void writeOpenTag(Element node, int depth) {       indent(depth);        sb.append(_lt);       sb.append(node.getName());        for (Enumeration keys = node.getAttributeKeys();keys.hasMoreElements();) {            String key = keys.nextElement().toString();           sb.append(_sp).append(key);           sb.append(_eq).append(_dqt);          sb.append(node.getAttributeValue(key).toString());            sb.append(_dqt);      }    }    private void writeCloseTag(Element node, int depth) {       if (node.hasChildren()) {         sb.append(_lt).append(node.getName());        } else {          sb.append(_cl);       }     sb.append(_gt).append(_nl);    }}
    

    This line:

    private static final byte[] _nl = System.getProperty("line.separator").getBytes();
    

    is originally a NullPointerException because line.separator is not well supported. The line terminator standard for XML is CR/LF, so you can use:

    private static final byte[] _nl = { '\r', '\n' };
    
  • Creating ENUM dynamically string Array

    Hello

    I was wondering if it was possible to create an ENUM dynamically? For example, I would like to read values from an array of strings and use each element to add a new element in the control of the ENUM. If this is not possible, how to set up a structure deal to read values from an array of strings as an ENUM would normally be able to? It would help enormously if I didn't have to manually enter the string name for each particular case. Thank you very much.

    Ditto the comments of Dan.

    If you ask because you want to just save you a lot of work when editing, you could wrie all your channels to a ring and then right-click and choose replace > enum and the object will change to an enum with all the ropes of the ring.

    Be sure to include the case by default since you are dealing with strings.

    I hope this helps,

    Ben

  • create a hexadecimal string

    I want to send a hexadecimal string to a device.

    0000 0000 0006 0103 2 0001 07D

    If I send the string as written above, I get the expected response.

    2 07D is a register number and I would like the user to be able to choose the register. I created this code to see if I could insert the hex string required in the full string. (Note that string constants are in hexadecimal display)

    It works very well, producing the correct hexadecimal string, 0000 0000 0006 0103 2 0001 07D.  I send the string and the device reacts as expected.

    Since I want the user to be able to choose the registry I created a mechanism for it and replaced the constant substring (07D 2) with this code.

    (Note that the value entered in the D - Reg control no. 2003)

    Although the conversion of a hexadecimal string of product 07D I16 control 2, replace the hexagonal result string of the function subset string produces this, 0000 0000 0006 0103 3037 4432 0001.

    Can anyone offer advice or perhaps suggest another method?

    Thank you.

    John.

    First of all, when the formatting strings, you're better off the coast using the Vi of string marker rather than replace elements in a string. However, in this case your string format is retrungin you the representation of ASCII number and, therefore, you get an incorrect value in the output string. What you need to do is to replace the bytes of the string with the actual binary data, not the ASCII representation. One way to do this is to simply flatten the number to a string, then replace the bytes. You can also convert the number as well, and then replace the data. Here is an example.

  • expression regular-insert to create a 'new' string expression in the correct position

    I have sample data in table T, and I sample how I want more than data output of the query output.
    with T as
    (
    select 'CREATE OR REPLACE PACKAGE BODY "YYY"."PACKAGEONE" IS' s from dual union all
    select 'Create or REPLACE PACKAGE BODY "ZZZ"."PACKAGETWO" IS' s from dual
    )   
    select REGEXP_REPLACE(T.s, '^.PACKAGE BODY$','(\1)_new',1,1,'i') as s from T;
    /*
    Expected output:
    CREATE OR REPLACE PACKAGE BODY "YYY"."PACKAGEONE_new" IS
    Create OR REPLACE PACKAGE BODY "ZZZ"."PACKAGETWO_new" IS
    */
    All data as a result of model:
    CREATE OR REPLACE PACKAGE BODY "[owner]"."[name]" IS
    Where [owner] can be any string. In the examples of data we have for example XXX and YYY values here.
    And [name] can be any string. In the sample data we have for example values PACKAGEONE and PACKAGETWO here.
    Other parts of the chain is fixed and rest as you see.
    In accordance with the request of expected results should replace substring '[owner] '. ' ' [name] ' '[owner] '. "" [name] _new.

    How can I write this query?
    I think that I have in some way should in regular expression counts the positions of double quotes to achieve the expected result, but I don't know how.
    SQL> ed
    Wrote file afiedt.buf
    
      1  with T as
      2  (
      3  select 'CREATE OR REPLACE PACKAGE BODY "YYY"."PACKAGEONE" IS' s from dual union all
      4  select 'Create or REPLACE PACKAGE BODY "ZZZ"."PACKAGETWO" IS' s from dual
      5  )
      6* select REGEXP_REPLACE(T.s, '"([^.]+\.[^.]+)"','"\1_new"') as s from T
    SQL> /
    
    S
    ----------------------------------------------------------------------------------------
    CREATE OR REPLACE PACKAGE BODY "YYY"."PACKAGEONE_new" IS
    Create or REPLACE PACKAGE BODY "ZZZ"."PACKAGETWO_new" IS
    
    SQL>
    
  • Can I create a substitution string?

    Hello!

    Can I create a new chain of substitution? Y at - it all the substitution string that it can used?
    Anyone can say more about the substitution string?


    Kind regards
    Priscila Britto

    HI -.

    You can create chains of substitution under shared components / definition.

    Good luck.

  • Creating a custom string of text

    I have 4 text boxes. They are events, city, Email and chain

    If Las Vegas is entered in the City text box, I want the text box to a string to read "City: Las Vegas.

    If BK is entered in the event text box and Las Vegas entered the City text box, I want the text box to a string to read "Event: BK City: Las Vegas.

    If [email protected] entered in the Email text box, and there is no data in the event, or the city of text boxes, I want the text box string read ' Email: [email protected] .

    I can enter data into the string text box, but if one of the 3 text boxes is empty my text string box reads something like that ' event: Email: . " [email protected] City: '

    If one of the event, city, and/or Email text boxes is empty, I don't want the text associated with the data will appear in the Srtring text box.

    I'm a novice at javascript. Any help is very appreciated.

    Ok. You must instead use the mouse upward, and could be replaced by the script:

    Script mouse upward to a button

    (function () {}

    Get the field values as strings

    sEvent var = this.getField("Event").valueAsString;

    var sCity = this.getField("City").valueAsString;

    var sEmail = this.getField("Email").valueAsString;

    Get a reference to the output field

    var fOutput = this.getField ("String");

    var sOutput = "", aOutput = [];  Initialize the production chain and table

    Set the output array

    If (sEvent) {}

    aOutput.push ("Event:" + sEvent);

    }

    If (sCity) {}

    aOutput.push ("City:" + sCity);

    }

    If (sEmail) {}

    aOutput.push ("Email:" + sEmail);

    }

    Join the elements of the array into a string, separated by a space

    If (aOutput.length > 0) {}

    sOutput = aOutput.join("");

    }

    Set the value of the field on the output string

    fOutput.value = sOutput;

    })();

    If you want it to happen automatically, you can use the custom calculation script next to the field "String".

    Custom string field calculation script

    (function () {}

    Get the field values as strings

    sEvent var = this.getField("Event").valueAsString;

    var sCity = this.getField("City").valueAsString;

    var sEmail = this.getField("Email").valueAsString;

    var sOutput = "", aOutput = [];  Initialize the production chain and table

    Set the output array

    If (sEvent) {}

    aOutput.push ("Event:" + sEvent);

    }

    If (sCity) {}

    aOutput.push ("City:" + sCity);

    }

    If (sEmail) {}

    aOutput.push ("Email:" + sEmail);

    }

    Join the elements of the array into a string, separated by a space

    If (aOutput.length > 0) {}

    sOutput = aOutput.join("");

    }

    Set the value of this field to the output string

    Event.Value = sOutput;

    })();

Maybe you are looking for