Comprehension: How many threads can be created? 1 or more? What are the process orders like (sequential or parallel)?

15 views
Skip to first unread message

Arne Mailand

unread,
Oct 17, 2016, 1:04:08 PM10/17/16
to App Inventor Open Source Development
When I have a method which creates a thread like this:

@SimpleFunction
public void Get() {
 // Capture property values in local variables before running
  // asynchronously.
 final CapturedProperties webProps = capturePropertyValues("Get");

AsynchUtil.runAsynchronously(new Runnable() { @Override
public void run() {

try {

       performRequest(webProps, null, null);
     } catch (FileUtil.FileException e) {
       form.dispatchErrorOccurredEvent(Web.this, "Get",
           e.getErrorMessageNumber());
     } catch (Exception e) {
       form.dispatchErrorOccurredEvent(Web.this, "Get",
           ErrorMessages.ERROR_WEB_UNABLE_TO_GET, webProps.urlString);

} }

});

} 



What will happen, when I call that method from the GUI thread serveral times simultaneously, with different parameters? Will the thread called a moment later start being processed after the first called thread has finished, or will both run simultaneously?

I testet this by writing a thread code which sends a file from the path which is given by the parameter. Then I wrote an app with a button, which initializes a socket and then starts that thread 2 times simultaneously with different file path parameters (first one is pointing a text file full of "AAAAA", the second one a text file full of "BBBBB"). I clicked that button and then looked on the server side what was coming in. The result was that the second file data (the "B"-army) was arriving after the last "A" of the A army from the first file.

From this I could assume that the threads are being processed sequentially (one by one) and not simultaneously.

But I am not sure about this. It is possible that the BufferedInputStream is blocking the input stream from the second thread until the first one has finished reading the AAA file in. Could this be happening? Is a thread being blocked, while it cant write data into the buffer, or will it just proceed after given the command to the bufferstream handler or what ever (shall I consider the buffered streaming thing like another thread of its own?).

I really would appreciate some coachings on this.

Thank you
Reply all
Reply to author
Forward
0 new messages