Example of thread

Is there an example (simple and easy to understand) a process running in a thread. I'm a Java developer and I have read tons of documents on c son, but his little about Greek to me and I don't know anything about what libraries are available on the PB. I coiuld use a working on the PlayBook example. If such an animal exists.

Channels on GitHub sample shows an app PlayBook with pthreads.

NDK 2.0:

https://github.com/BlackBerry/NDK-samples/tree/master/channels

BB10 Beta:

https://github.com/BlackBerry/NDK-samples/tree/next/channels

Tags: BlackBerry Developers

Similar Questions

  • thread and TSVs locks

    Dear experts threads,

    are there side effects if I use the macro "GetPointerTo" and "ReleasePointerTo" inside a thread lock, which is in the code located between CmtGetLock and CmtReleaseLock?

    Phrased differently, what type of sequence is best if I need to edit a TSV in a piece of code that should be accessible only from a single thread at a time:

    1)

    CmtGetLock

    ...

    CmtReleaseLock

    GetPointerTo

    ...

    ReleasePointerTo

    CmtGetLock

    ...

    CmtReleaseLock

    OR

    2)

    CmtGetLock

    ...

    GetPointerTo

    ...

    ReleasePointerTo

    ...

    CmtReleaseLock

    Thank you!

    Wolfgang

    Hi, Wolfgang.

    GetPointerTo... will block until the thread that holds the pointer releases, then the CmtGetLock() and CmtReleaseLock() calls are not necessary, unless they protect some other variables, in which case sequence 2) is the way to go.

    Remember that if you use multiple thread safe variables or multiple locks thread, and you need to use more than one at any time, each thread must obtain and release pointers / locking in the same order. This avoids the possibility of blocking. In addition, each thread must release the resource as soon as possible.

    Example (using thread locking):

    If (!.) CmtGetLock (lock1))

    {

    If (!.) CmtGetLock (lock2)) / / Get QL2 only when you hold lock1

    {

    ...

    CmtReleaseLock (lock2);  Always communicated QL2 before lock1

    }

    CmtReleaseLock (lock1);

    }

    Kind regards

    Colin.

  • Different thread field label update

    Hello

    I need to update the label on a buttonfield.  It's pretty simple to do when it is selected.  The problem is this: I want to trigger a web update, which runs on its own thread.  When the update is complete, I need to change the label field once again, this time by the new thread (which makes the update).

    I could be missing something really simple here. Any help would be appreciated.

    In General, you get eventlock of the application when you perform the update of the screen.

    for example:

    Thread t = new Thread (new Runnable()

    {

    public void run()

    {

    updateLabel();

    }

    });

    Private Sub updateLabel()

    {

    {Synchronized (application.getEventLock)}

    mybutton.setText ("new Text");

    }

    }

    Cheers.

  • Very old Threads on the top of the list

    Anyone else notice that lately, old son (unchanged) appear in the top positions of the list of threads? Example: this thread is number 2 in my list now, changed in September 2007.

    Gossweiler beat

    Switzerland

    Beat,

    He is an active spammer in the forum, the display about once a minute.  Maybe you've seen his posts?  When he published on a very old thread, it appears at the top of the list even if his post is deleted immediately.

    John

    John G. Blair Studio

  • My category of bookmarks in the toolbar has a logo of Trojan on four of the dropdown menu items.

    I have a desktop Mac G5 with OX 10.5.8. My Safari browser has been hacked with malware of TH, and so I removed it because it is too old to update to the Mavericks.

    I am now using Firefox. I now see that the Trojan horse is rooted in my bookmarks bar, on the drop-down menu Options. I was trouble reset Firefox and I can't the Malwarebytes that I downloaded to open and run. I deleted the history, cookies, cache them on my computer. I also deleted the Java, MSN and email old, mail and setting the hard drive.

    I'm a Low-Tech techno. Thank you for your ideas,

    svidor

    You are able to give screenshots or other information so that we know more about your problem.

    I don't know what the Trojan horse is / was, but there were a few reports of pseudo ransomware. This requires money and creates the impression that Firefox is locked. If you're lucky and you have this kind of problem, it is easy to get out of.

    If you have book marked sites with malware Firefox rents an option to forget the sites that can solve the problem.

  • Use of root for the system volume is 95%, var/ftp uses all

    Hello

    I have a ReadNas 102 and lately I have these error messages using the root of the system volume is 95%. After checking the files/var, I noticed that desired used all available space. I had FTP enabled for some files and it seems that the content of these files is copied to the folder var/ftp.

    Perhaps a matter of newbe 'stupid', but is - it normal that this folder/var/ftp is totally used.

    Second question: How can I safely remove the content of this file/var/ftp?

    Thanks in advance,

    Jan

    Hello.
    The ibdata1 still growing is not a ReadyNAS problem, but a problem of MySQL, may be triggered or worsened by track LogAnalyzer to commit requests.
    There is a lot of discussion online about this. But it seems that there is no easy solution to reduce its size.
    An example of thread: http://stackoverflow.com/questions/3456159/how-to-shrink-purge-ibdata1-file-in-mysql
    If you don't use it, I suggest delete LogAnalyzer and mysql-server.

  • Open MP question

    Hello

    It's all right, just a question out of curiosity:

    using

    #pragma omp for

    before a for loop specifies that the iterations of the associated loop will be executed in parallel.

    My question: suppose I have a loop with 10000 iterations and two threads will be generated; thread, will be calculated first iterations 5000 while the second begins at 5000 index, it will work on odd/even clues or it is random, or...

    Thank you!

    Hello

    If you do not specify a schedule using the schedule clause, the default value is the static calendar, where the iterations of the loop are divided in almost equal sizes between threads. So in your example, a thread will execute the iterations of the loop 0 - 4999 and the second thread will run iterations 5000 and 9999.  You can still see thread that runs that iteration by something like this:

    #omp parallel for
    for (int i = 0; i < 10000; i++)
       printf ("Iteration %d executed by thread %d", i, omp_get_thread_num())
    

    An identifier, is attributed to each thread in the parallel region with the "master" thread having the id 0. This value is returned by omp_get_thread_num(). In the case above, the 'chunk' size is 5000.  You can change this by specifying the schedule (static, chuncksize) clause:

    #omp parallel for schedule (static, 1000)
    for (int i = 0; i < 10000; i++)
       printf ("Iteration %d executed by thread %d", i, omp_get_thread_num())
    

    Here, each thread will run 1000 iterations of the loop, and then pick up the 'segment' available after 1000 iterations, and so forth until loop all of the iteations are executed.

    You can also specify dynamic and guided schedules that are useful when the iterations of the loop are not load balanced. See section 2.5.1 features of OpenMP 2.5 for more details.

  • Does anyone can hack my computer asking me to right click on my computer, and then press Ctrl + r?

    After a recent phone a supposed Technician Microsoft, where the person asked us to perform all kinds of things on our computer and we showed a list of all corrupt files, is it possible they are running malware on my computer?  I know that it was not clever to fall for her, but there was a lot of things now and we just took panic.

    If someone could give some tips would be great as we are concerned, lose us all the files or have accounts hacked etc.

    Thank you
    Clodagh

    It depends on what you entered in the box run after you press CTRL + R.

    As a general rule, these scammers will tell you type "eventvwr" after pressing CTRL + R and then scared you to have you look at all the 'warnings' and 'Mistakes' or they have type you a command and magically know what is on your computer.  See, for example, this thread Microsoft Answers:

    She forced me to type "cmd" in run and when the command prompt came I type in "assoc". When the list of information showed she was reading on line 3, ID my CSLID and all the numbers that followed were accurate.

    As long as you don't allow the caller to access your computer (usually by LogMeIn or some similar site and enter a password, they give you), you're probably OK.

  • Starling?

    Does anyone have the demos Starling or apps working?

    By experiencing the problems alpha device running.

    Unfortunately, RIM has decided to delay support Stage3D and other new technologies AS3 (for example workers/threads) at a later, unspecified date, but after lance BB10. That's why Starling and other managers who rely on Stage3D not usable at the moment. More info in the road map under "Update running"

  • How to develop BlackBeery Ui

    I want to develop the UI for a screen which I join... on ehelp me please to write code for the user interface

    akhilmuppa wrote:

    Main box is a text box, and it will scroll vertically and horizontally...

    Yes, really, I have problem with header, I've tried in many ways with many managers, but it does not display the two textfielld and button .so please help me solve this problem... As I referred to it a few docs but I force get the solution

    OK, then you create your screen with both VERTICAL_SCROLL and HORIZONTAL_SCROLL flags. The main area Manager (which is not directly visible to you if you can get the reference through getMainManager) is a VerticalFieldManager, so it will hold the fields vertically (duh!). However, thanks to the HORIZONTAL_SCROLL indicator, it will allow wider than the screen fields to get what they want and will be able to scroll horizontally - either programmatically (setHorizontalScroll) or 'naturally' when the focus moves outside the visible area.

    As for the problem with the textfield and button, there are two ways to solve it.

    For example, if you searched "width-hungry" as I suggested, you would have found, for example, this thread:

    EditField and checkboxfield on the same line

    Take a look at the solution - it's one of the ways to do so: simply create a field that will be limited to how much of the piece.

    The second solution would be to create a Manager customized for this particular configuration of TextField left and ButtonField right. The Manager will always have exactly two fields, in this exact order, so you can write his sublayout invoking it.

    So, what does ' protected void sublayout (int maxWidth, maxHeight) ? It does the following things:

    (1) receives the maximum width and height it can occupy in the parent Manager (see maxWidth and maxHeight parameters);

    (2) tells the Manager (managed fields) how room child within this handler they can get (using layoutChild (child of field, int height, int width)). After that (and only after that) he knows how this child will be actually using child.getExtent (any form) or (if you want width and height separately) child.getWidth()/child.getHeight (). It is normal that any Manager to expose a child, get its dimensions, adjust the width and height according to the remaining information then continue carrying the children in the same way.

    (3) positions of its children using the setPositionChild (child field, int x, int y) call. Positions are relative to its upper-left corner (which is (0,0)).

    (4) calculates the height and width that result and sets using setExtent (int width, int height).

    Try to write the handler using these data as well as the link provided Simon and come back here if you still have problems. By the way, take a look at sublayout to JustifiedEvenlySpacedHorizontalFieldManager for a good example.

  • Animated GIF dialog HTTP connection

    Hello

    I created a screen of dialogue GIF animated using pop-up screen and I have to show it when an application connects to the server using httpconnection. So the problem is when I create dialogue and display it on the screen the network connection is not happeneing animation only one thread is running.

    For example

    I have a class called AnimatedDialog that draws the gif image using a thread.

    My Httpconnection is awritten in function connectToServer()

    It is how I call it

    AnimatedDialog.show)

    Thread t = new Thread (new Runnable ({}

    public void run() {}

    connectToServer()

    }});

    t.Start ();

    Any suggestion of implementation of such a screen. I can't update the lively dialog of HttpConnection. Once the httpconnection is completed, the dialog box, I closed.

    Depends on what you do inside your AnimatedDialog.show ().  If you use UiApplication.getUiApplication () .pushModalScreen (...) in there, that's what you'll get - it will not go forward until the screen is out.

    Why is it that you do not reverse the order of the actions?  For example:

    Thread t = new Thread(new Runnable()
        public void run() {
            connectToServer();
            AnimatedDialog.hide(); // or pop it some other way
        }
    });
    
    t.start();
    
    AnimatedDialog.show();
    

    In this way, you start the thread and display the dialog box indicating that you are a background operation (already!)...

  • You can replace &amp; #xd; with &amp; #xa; in Indesign (xml)?

    Hey guys,.

    When you tag an item in Indesign, get you & #xd; for line breaks. I need it to be & #xa;

    I tried the following:

    for (i = 0; i < myDocument.selection.length; i ++) {}

    current = myDocument.selection;

    currentText [i] = .silence current [i];

    currentText [i] replace ('& #xD ',' & #xA');

    }

    Any suggestions? Thanks in advance!

    XSLT is a web standard. Amazon gives 75 pages when looking for books of xslt.

    You know that InDesign provides that only the old version 1 defined here Of XSL Transformations.

    With Google I found much more options concerning the areas mentioned on this page: whitespace delicate manipulation in XSLunfortunately only incomplete extracts.

    StackExchange is a good site for XSLT issues, for example this thread you will get close. Don't forget that you need to change the version number to 1.

    Anyway, you first need to decide (and let us know) If you want your changes in the existing (as attempted with your script) document or for example on import or export.

    Dirk

  • rich outputtext rich text input

    use jdev11.1.1.5.0

    I had the question that some stupid,.

    How to convert or casting

    richinputtext to richoutputtext?

    is it possible. just, I had a doubt? any1 clarify

    Published by: Les on 24 Sep 2011 03:43

    Hello..
    > value of inputtext want to show in the output text
    I create a simple example for thread control after a few times, it will be useful

    Re: backing bean - scope pageflow

  • Monitoring of JMX and operations on processors

    Hello

    3 questions:

    1.) is it possible that I can view the current status of a window of time data (i.e. to retrieve a list of events) through the JMX api?

    2.) is it possible to clear the contents of processor/channel without having to cancel the deployment of the application? (even implicitly by send a global heartbeat that will be cascading on all processors)

    3.) just to confirm, OSGI stop command causes all heaps allocated to a particular application to be a candidate at the GC?

    Kind regards
    Jarell

    Hello

    (1) No, there is no JMX API to do this. You may, however, join these notice and release the whole relationship (RSTREAM).

    (2) No, this would be modeled in the application, for example, by defining queries CQL to use a window of the application-timestamped and sending heartbeats.

    (3) Yes, for example, any thread that could be used by an adapter would have been let go. Note, however, that if this is a custom user provided adapter, it is always the responsibility of the user to free resources that could have been acquired in the recall of suspend().

  • How organaize out in MT programms?

    Hello, I started to learn some multi-threaded programms and Atomic variables. But a question about the simple example.
    public class Main {
        
        /** Creates a new instance of Main */
        public Main() {
        }
    
        public static void main(String[] args) {
            new TestThread("T1");
            new TestThread("T2");
            new TestThread("T3");
            new TestThread("T4");
            new TestThread("T5");
            new TestThread("T6");
            new TestThread("T7");
            new TestThread("T8");
            new TestThread("T9");  
            new TestThread("T10");
            new TestThread("T12");
            new TestThread("T13");
            new TestThread("T14");
            new TestThread("T15");
            new TestThread("T16");       
            new TestThread("T17");
            new TestThread("T18");
            new TestThread("T19");
            new TestThread("T20");
            new TestThread("T21");
            new TestThread("T22");
    
    
        }
        
    }
    
    public class TestThread implements Runnable{
        
        private Thread t;
        
        /** Creates a new instance of TestThread */
        public TestThread(String name) {
            t = new Thread(this, name);
            System.out.println("Thread " + t.getName() + ": is created.");
            t.start();
        }
        
        public void run() {
            ProgGenerator pg = ProgGenerator.getInstance();
            for (int i = 0; i < 2; i ++) {
                int k = pg.next();
                synchronized (System.class) {
                    System.out.println("Thread " + t.getName() + ": " + k);
                }
    
            }
        } 
    }
    
    public class ProgGenerator {
        
        private static ProgGenerator instance = new ProgGenerator();
        private AtomicInteger currentInt;
        
        /** Creates a new instance of ProgGenerator */
        private ProgGenerator() {
            currentInt = new AtomicInteger(1);
        }
        
        public static ProgGenerator getInstance() {
            return instance;
        }
        
        public int next() {
            int result;
            do{
                result = currentInt.get();
            }while(!currentInt.compareAndSet(result, result + 2));
            return result + 2;
        }
    }
    When I run it I have something like this:
    Thread T1: is created.
    Thread T2: is created.
    Thread T3: is created.
    Thread T4: is created.
    Thread T5: is created.
    Thread T6: is created.
    Thread T7: is created.
    Thread T8: is created.
    Thread T9: is created.
    Thread T10: is created.
    Thread T12: is created.
    Thread T13: is created.
    Thread T14: is created.
    Thread T15: is created.
    Thread T16: is created.
    Thread T17: is created.
    Thread T18: is created.
    Thread T19: is created.
    Thread T20: is created.
    Thread T21: is created.
    Thread T22: is created.
    Thread T1: 3
    Thread T1: 43
    Thread T2: 5
    Thread T2: 45
    Thread T21: 41
    Thread T21: 47
    Thread T20: 39
    Thread T20: 49
    Thread T19: 37
    Thread T19: 51
    Thread T18: 35
    Thread T18: 53
    Thread T17: 33
    Thread T17: 55
    Thread T16: 31
    Thread T16: 57
    Thread T15: 29
    Thread T15: 59
    Thread T14: 27
    Thread T14: 61
    Thread T13: 25
    Thread T13: 63
    Thread T12: 23
    Thread T12: 65
    Thread T10: 21
    Thread T10: 67
    Thread T9: 19
    Thread T9: 69
    Thread T8: 17
    Thread T8: 71
    Thread T7: 15
    Thread T7: 73
    Thread T6: 13
    Thread T6: 75
    Thread T5: 11
    Thread T5: 77
    Thread T4: 9
    Thread T4: 79
    Thread T3: 7
    Thread T3: 81
    Thread T22: 83
    Thread T22: 85
    So, as you can see he is not out in order of numbering of the threads (thread number 22 is near the number 3 of the thread, but it's ok). And of course it is there no error, but I cann't find reseans why the values in this son are mixed? I try to explain what I mean. We get this:
    Thread T1: 3
    Thread T1: 43
    Thread T2: 5
    Thread T2: 45
    Thread T21: 41
    Thread T21: 47
    But not for example:
    Thread T1: 3
    Thread T1: 5
    Thread T2: 7
    Thread T2: 9
    Thread T21: 11
    Thread T21: 13
    I can only afford, this thread can be stopped between updating the value and display it. This thread 1 first time set 3 and exit it, but then all variable son increased thread 41 but not make the exit, then walk again enter the loop value 43 and exit at the same time. If so, it's something strange that about 20 threads display nothing until the thread 1 output.
    Is there a mistake? Or just everything is ok? And this code works correctly in multi-threaded program if we speak out (I mean that the update of currentInt is safe when you work with threads and each of them get good value when access)?

    Published by: sphinks 16 January 2011 13:45

    Published by: sphinks 16 January 2011 13:55

    Hi Sphinks,

    If you have needs on order of execution of the code running in java different Threads, you must take care through the synchronization of this order yourself. Without making an attempt to describe what is happening inside your computer while your program is running, the output is to be expected and your description of the reason lies in a sort of handwaving.

    I like to think, however, that you can write an example program slightly less complicated which shows the AtomicInteger to work in a multi thread environment. How about having your Runnables does not print but store the values and have your main thread loop on them after they are all made to print "results"?

    Thank you p.s. use [code] - labels in the future.

Maybe you are looking for