Do I need to worry about concurrency issues in my Flex / AIR code?

I have a situation where I run several objects that, when they are ready to process some input data, call a handler.

This handler retrieves the dataset from the ArrayCollection of pending requests, assigns it to an object, and removes the dataset from the ArrayCollection.

(I cannot jump out of ArrayCollection because I need to find it in order to find a suitable dataset - it is not always the one on top).

Is it possible that two objects could call my handler in such a way that (1) the dataset is assigned to the first, (2) the same dataset is assigned to the second before its remote instance of the handler serving the first and I assume (3) the second instance handler errors when trying to delete a dataset from an ArrayCollection.

I am not familiar enough with the Flash Player runtime to find out if this failure scenario is possible, or if I need to take extra time to put some kind of lock in place to prevent it.


Edit: The answers still give glowing reviews for Flex, but I'm not sure if they answer the question. To be clear, I'm not trying to decide whether to use Flex.

If I have a method that:

  • Retrieves a piece of data from somewhere in an ArrayCollection
  • Something with this data.
  • Removes this data from an ArrayCollection array.

Is it possible that another call to the same method could make # 1 after the first call to # 1, but before it is # 3?

le dorfier, you said that Flex / AS "just works" - can you explain that it will "work" in this case?

+4
source share
3 answers

You do not need to do a lock, but you can track the order of changes in your state. The various asynchronous calls that are in the game can return and change the state of the model in an order different from when the asynchronous calls were issued.

Flex and AIR applications have a single-threaded programming model. However, their architecture is based on asynchronous I / O to interact with the server layer.

Now in a Java Swing or .NET Winforms application, you can interact with i / o on the return line flow and marshal the arguments / results to and from the main GUI stream. (These graphical user interface libraries do not allow other threads to change the state of objects / widgets of graphical tools, and, therefore, data interaction should be tied to other phonogram processing threads.)

In contrast, the i / o class library from Flex and AIR is written where these classes perform I / O asynchronously. For example, to perform an HTTP GET, the HttpSerivce send () method may be called, which is not a blocking call. Instead, an ActionScript3 closure may be provided to handle the result whenever the call completes and returns.

In the meantime, the Flex / AIR application may allow the graphical interface to continue to be fully interactive for the user. It can even display a progress indicator and / or a Cancel button.

Thus, it turns out that although the single-threaded Flex / AIR GUI model is simpler and simpler to program than multi-threaded Java Swing or .NET Winform applications, it is capable of the same complex user interface behavior as those rich client application styles.

A simple event-driven, single-threaded graphical interface, asynchronous I / O (through service calls and / or messaging), combined with closing ActionScript3 to handle results or failures, is Flex / AIR's secret recipe for world domination. (Of course, I should mention good support for properties, events, and good declarative or imperative data bindings, too, as part of this strategy for conquering the world.)

+8
source

The answer to your question, as you described it, is no. Although knowledge of event logging, event scheduling, priorities, asynchrony, etc. It is valuable, it remains a fact that you are doing the work of modifying the ArrayCollection within one function of the main thread, followed by a second call to this function, also in the main thread - so you have nothing to worry about in terms of concurrency: although it’s true, you, maybe you don’t know which object gets there first (for many reasons), you can be sure that the second will receive the work of work done by the first.

So no, you're good to go. Rock on!

+2
source

After digging into Flex and Actionscript for several months, I returned to .NET; and I'm a little overloaded with all the different modes that I need to choose, or, in turn, I have to choose and organize.

In contrast, Flex / AIR has a fairly simple but complete set of SDK calls for processing data and files, each of which has synchronous and asynchronous options. It is much easier to understand and use consistently.

Roger straight from my experience. Flex / AS # Just Works..NET, which is reduced (from parameter overload, IMHO). One consequence is that .NET better adapts edge scripts; but if Flex / AS3 can meet your requirements, it will probably make it easy. Think of the 80/20 rule (or probably better).

I think your question was addressed by Roger, but let me say the way I think I heard it.

Your method is single-threaded (along with other user interface actions) in the general user interface thread. But resources (files, dbms ports, etc.) usually go through a simple sequence, which you usually configure as follows:

  • Create an object of the required resource class,
  • Register an event handler for the return event on the object (for example, "fileonOpen"),
  • Call the async execution method for the object (for example, "file.open").
  • The UI event loop continues
  • Ultimately, the resource completes its method and launches the event handler that you registered, which now runs in the user interface thread. Perhaps the answer to your question is that the event handler receives an argument, which is the object to which it refers, so you can remove it from your collection. Presumably, your item is well-identified enough to prevent confusion with the collection to which it belongs. If this is a database result string, it seems to know its PK value. File objects have properties such as nativePath, isDirectory, parent (another File object), etc.
+1
source

All Articles