M362 2008 Exam (part 2) Flashcards

1
Q

Give a definition of a thread-safe class.

A

A class is considered thread-safe if its instances behave under concurrent method calls as if they were called sequentially. In other words, it is not possible for a multithreaded application to observe an instance of that class in an inconsistent state, i.e. a state that could not be observed by a single-threaded application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Show, using the example scenario, how class Account violates the definition of a thread-safe class.

A

For the example scenario, a sequential execution of
myAcc.credit(20);
myAcc.debit(15);
will lead to a balance of 15, but with two concurrent threads it could lead to a balance of 30. Consider that T2 is interrupted after computing the sum balance + 20. At that point T1 executes the call to debit,
leaving a balance of −5. Now T2 resumes execution and assigns 30 to balance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the general problem of which the scenario is an example?

A

This is an example of the lost update problem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Write a class BlockingAccount which is a thread safe version of Account, and in which, additionally, the debit operation blocks until balance is greater than or equal to the amount to be debited. Note: You must use Java’s built-in mechanisms, NOT the Java 1.5 concurrency utilities.

A
public class BlockingAccount
{
protected int balance;
public BlockingAccount (int balance)

{

this.balance = balance;

}

public synchronized void debit (int a)

{
while (balance < a)
{
wait();

}

balance = balance - a;

}

public synchronized void credit (int a)

{
balance = balance + a;
notifyAll();
}

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain two limitations of the built-in mechanisms used in the previous question and how they were addressed by the concurrency utilities introduced by Java 1.5.

A

Java’s built-in monitors are limited in the sense that they have a single implicit condition variable per lock and there is no possibility of retracting lock acquisition attempts.

The concurrency utilities introduced the Lock and Condition interfaces.

The former has a tryLock method that doesn’t block if the lock is not available, and the latter allows the developer to associate multiple explicit conditions to each lock. Note: The exact names of interfaces and methods do not have to be fully correct as long as the explanation is clear.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain and compare the thread safety levels of classes Account and BlockingAccount. Discuss why there is a need to identify various thread safety levels and what their existence implies for developers.

A

Account is thread-compatible because it does not use internal synchronisation and hence requires every method call to be externally synchronised.

BlockingAccount is thread-safe because no external synchronisation is necessary for calling its methods.

Identification of the various thread safety levels is necessary because there are different ways for making classes behave correctly in a concurrent setting (e.g. by making the data immutable or by various degrees of internal and external synchronisation). This means that class developers have to document precisely the class’s safety level and which (sequences of) methods, if any, require external synchronisation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe a schedule for the example scenario, but using BlockingAccount instead of Account, indicating for each thread the states it goes through in the Java Thread state model. Note: Assume the two threads are NOT in the NEW state. For full marks provide a schedule that uses three different states.

A

We assume both threads are in the RUNNABLE state.

One of them is scheduled for execution, let’s assume it is T1. It acquires the lock on the account, and starts evaluating the while condition. At this moment, T2 is scheduled for execution, it tries to obtain the lock, but since it is held by T1, T2 becomes BLOCKED.

Now T1 resumes execution, enters the while loop (because it is attempting to debit 15 from an account holding only 10) and calls wait.

This releases the lock and T1 gets into the WAITING state.

T2 is now able to get the lock, becomes RUNNABLE and executes the credit operation, which notifies T1.

T1 thus returns to the RUNNABLE state and completes the debit operation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Using a diagram or otherwise, name the standard tiers of a Java EE application and indicate the type of components associated with each tier.

A

Client Tier: Browser, applet, application client

Web Tier: Servlet, JSP, JavaBean

Business Tier: EJB, Entity class

Database / EIS Tier: DBMS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain the role in Java EE applications of

  • stateful EJB session beans

Discuss how each of these might be used in implementing the web application outlined in the scenario above.

A

Stateful EJBs
EJB session beans are objects that contain the application logic, providing business services to clients.
In a stateful bean, the state (i.e. the value of the bean’s instance variables) is kept across multiple calls to the bean’s methods. A classic example is a shopping cart in an online shop. The shopping cart has to keep its state (i.e. the products it contains) across multiple interactions with the client, who might add and remove products from the cart.

In the scenario, stateful EJB session beans could be used to keep track of the user’s preferences for location, activities, accommodation and so on during the session

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Explain the role in Java EE applications of

  • stateless EJB session beans

Discuss how each of these might be used in implementing the web application outlined in the scenario above.

A

Stateless EJBs
In a stateless bean, the state is discarded after each method call, i.e. a session with a stateless bean only lasts for the duration of a single method call.

This makes stateless beans ideal to provide one-off services that are performed always in the same way, independently of the actual client invoking it. For example, a database query can be seen as a complete session by itself, and it isn’t necessary to keep a record of which client executed which query. Therefore a single stateless bean can provide multiple methods, each one implementing an independent query.
In the scenario, stateless EJB session beans could be used for example in retrieving the list of accommodation for a particular location

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Explain the role in Java EE applications of

  • transactions

Discuss how each of these might be used in implementing the web application outlined in the scenario above.

A

Transactions
A transaction is a sequence of operations which we want to be performed atomically, that is to be performed in its entirety, or not performed at all.

The classic example of a transaction is a transfer of funds from one account to another in a bank application. This requires a sequence of operations including debiting one account and crediting the other. It is important that either all the operations take place, or that none of the operations takes place.
In the scenario, transactions will be necessary when booking accommodation to ensure that any booking operations (including payment) complete fully or are not carried out at all.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Explain how HTTP servlets deal with the following issues:

  • Handling concurrent requests from multiple clients;
A

Handling concurrent requests from multiple clients
For the standard situation of a multi-threaded servlet, the Web container will create and run a separate thread for the service method that is invoked in response to each request.

The helper methods such as doGet or doPost which will be invoked by the service method must be written to take account of this.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Explain how HTTP servlets deal with the following issues:

  • Avoiding problems with concurrent access to shared data.
A

Avoiding problems with concurrent access to shared data.
Any data stored in variables declared locally to servlet methods is threadsafe, because each thread has its own copy of local variable data.
By contrast, instance variables** or **static variables** are **not thread-safe as they are shared between any threads being run concurrently by the servlet.

Code that updates instance data or static data, must use synchronization, so that at most one thread at a time can be carrying out an update.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Explain whether and how the issues from part (c below) might arise in the tourist information web application outlined in the scenario above.

  • Handling concurrent requests from multiple clients;
  • Avoiding problems with concurrent access to shared data.
A

There may be many users simultaneously using the tourist information site, each searching for different regions, activities and so on – each user request will require a separate service thread for the servlet (or JSP) that responds to the user request.
Much of the data will belong to a particular request and so will be local to a servlet method and not vulnerable to multi-threading interference.
Data that must persist throughout a session across several requests must be stored either in a JavaBean associated with a session object or perhaps in a database.

This could apply to the preferences for each user as it is important that users do not accidentally update each others preferences. If stored in a session object then synchronization is not usually needed since each user only has one request active at a time – if this cannot be guaranteed then code that updates the session object should be synchronized.
It is unlikely that instance data or static data will be used, although one possible application would be in keeping track of the number of users online at any given time – updating any such counter variable should be a synchronized operation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

List and discuss three additional issues to consider if we wanted to provide access to the tourist information system from mobile devices such as phones or PDAs.

A

Three possible issues that arise are:

  • *Limited resources** on phones/PDAs - because of the smaller screen space and other resources, the web tier and client tier would need to allow for different formatting of the interface – for example as a WAP interface rather than a standard web browser, or perhaps an application client or applet interface
  • *Communication bandwidth** may be limited or more unreliable than with fixed network connections – as above this may require a different interface (less complex maps for example) and emphasises the need for transactions etc to cope with intermittent communications failure.
  • *Security issues** - interception of mobile communications is, in principle, easier than for fixed lines. For most transactions on this site security would probably not be a major issue, but when booking accommodation the payment process must be secure.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is meant by a heterogeneous system?

A

A heterogeneous system is one implemented using more than one kind of computer, operating system, software or communication protocol.

17
Q

Why are heterogeneous systems of particular interest in distributed computing?

A

Heterogeneous systems are of particular interest in distributed computing because distributed computing in a wide context inevitably involves heterogeneity, due to the variety of systems in existence.
[Alternative answers include
• Legacy systems may exist or systems may have been developed by different parties at different locations and times, leading to heterogeneity.
• We cannot ignore heterogeneity if we hope to achieve interoperability or reusability of systems in a distributed context.
• It may be worth getting heterogeneous systems to talk to one another, for such reasons as using a legacy database, or widening access to distributed users.]

18
Q

Give a definition of middleware.

A

Middleware may be defined as any software that provides an intervening layer between two communicating systems, providing the ability to make communication between the systems **transparent. **

OR software that masks the heterogeneity of an underlying system

19
Q

Explain what is meant by homogeneous and heterogeneous middleware, and give an example of each.

A

Homogeneous middleware is middleware in which all parties are assumed to be implemented in the same language and running on the same platform.

Heterogeneous middleware is middleware in which no assumptions are made about a shared language or a common platform.

Examples:
• homogeneous: Java RMI
• heterogeneous: CORBA

20
Q

Heterogeneous middleware is more flexible than homogeneous middleware, but has higher overheads. Give two examples of such overheads.

A

Overheads:
additional communication overheads, due to their flexibility and the requirement to translate between heterogeneous representations
• heterogeneous middleware requires the use of an IDL representing features of multiple languages, as opposed to a common interface language (such as Java interface descriptions on both sides).

Interface Definition Language (IDL)

21
Q

Would you consider XML to be a form of middleware? Explain.

A

No, because XML is not a layer; it is just a way of representing a communication.

22
Q

Name two security services that are commonly employed in the database tier of the n-tier model and explain how they are put to use in this context.

A

Possible services include the following (only two were asked for)

  • Confidentiality, used to obscure stored information, e.g., encrypted passwords or records.
  • Integrity, used to check contents of stored files. This could be used on serialized data, e.g., to ensure that it was not altered while on a disk, or it could be used to check the integrity of a database file.
  • Authentication, used to check whether a user or caller is allowed to access a file or record.
  • Auditing, used to keep track of actions carried out by users or traffic on a system.
23
Q

State one advantage of using each service you discussed in this context.

  • Confidentiality, used to obscure stored information, e.g., encrypted passwords or records.
  • Integrity, used to check contents of stored files. This could be used on serialized data, e.g., to ensure that it was not altered while on a disk, or it could be used to check the integrity of a database file.
  • Authentication, used to check whether a user or caller is allowed to access a file or record.
  • Auditing, used to keep track of actions carried out by users or traffic on a system.
A

Advantages (only two were asked for but they must relate to the two services identified in (i) above)

  • Confidentiality – security of records is enhanced;
  • Integrity – increased robustness / security;
  • Authentication – reduced risk of unauthorised access / modification etc.;
  • Auditing – increased non-repudiation, i.e. increased ability to determine who is responsible for actions or issues.
24
Q

Explain the difference between a block cipher and a stream cipher.

A

A block cipher is one that operates on chunks of data at a time, called blocks,

whereas a stream cipher operates on a stream of data, typically a bit or a byte at a time. (This leads to differences in the way these ciphers are implemented, but the main distinction to make is the one above.)

25
Q

Which of these ciphers would you typically use in wireless communication? Explain why.

A

You would be most likely to use a stream cipher for wireless communication
This is because

  • Stream ciphers are computationally cheaper. This is particularly useful in this context, since computing resources and bandwidth are typically more limited
  • Communications in wireless communications are of unpredictable length and so are likely to suffer from a frequent requirement for padding or truncating if a block cipher is used (this again relates to computational requirements / efficiency).