By Day 7 , write a 2- to 3-page paper evaluating the implementation of the sort
ID: 3844832 • Letter: B
Question
By Day 7, write a 2- to 3-page paper evaluating the implementation of the sort algorithm. Answer the following questions:
What are the data integrity concerns due to concurrency control?
Implementation is correct, what protections are in place to ensure atomicity and consistency?
Provide specifics about the data integrity problems you encountered and explain the modifications that will be necessary to correct the data integrity and concurrency issues.
Include in your analysis an explanation of the operation of the threaded implementation, and if there are data integrity issues, suggest one or more modifications to the implementation to resolve these concerns.
Explanation / Answer
Threaded Implementation
In a solitary client database, the client can alter information in the database without sympathy toward different clients changing the same information in the meantime. Notwithstanding, in a multiuser database, the announcements inside of different synchronous exchanges can redesign the same information. Exchanges executing in the meantime need to create significant and steady results. Accordingly, control of information simultaneousness and information consistency is fundamental in a multiuser database.
To portray reliable exchange conduct when exchanges keep running in the meantime, database specialists have characterized an exchange disconnection model called serializability. The serializable method of exchange conduct tries to guarantee that exchanges keep running in a manner that they seem, by all accounts, to be executed each one in turn, or serially, instead of simultaneously. While this level of confinement between exchanges is by and large attractive, running numerous applications in this mode can truly bargain application throughput. Complete disconnection of simultaneously running exchanges could imply that one exchange can't perform a supplement into a table being questioned by another exchange. To put it plainly, certifiable contemplations as a rule require a trade off between impeccable exchange segregation and execution. (docs.oracle.com)
Working frameworks oversee assets for client applications, yet don't give an instrument to applications to gathering operations into sensibly predictable upgrades. The consistency of utilization information can be undermined by framework disappointments and simultaneousness. Consistency is ensured by permitting basic operations happen molecularly and in segregation from whatever is left of the framework. Systems for information consistency exist at various layers of the product stack. Case in point, locks use common avoidance to give consistency to client level information structures, and database exchanges give reliable upgrades to database-oversaw auxiliary stockpiling.
Shockingly, the POSIX framework call API has lingered behind in giving backing to steady overhauls to OS-oversaw assets. The OS implements a solitary framework call molecularly and in separation, yet it is troublesome, if not unimaginable, for application to extend these assurances to anprocess that is excessively mind boggling, making it impossible to right in a solitary framework call. This paper proposes adding framework exchanges to the framework call API. A framework exchange executes a progression of framework brings in disconnection from whatever is left of the framework and molecularly distributes the impacts to whatever remains of the framework. Framework exchanges give a straightforward and intense route for application to direct consistency prerequisites for simultaneous operation to the OS.
Just the application sees when it is information is in a predictable state, yet framework assets that are basic to guaranteeing reliable upgrades, for example, the record framework, are outdoor of client control. In straightforward cases, developers can serialize operations by utilizing a solitary framework call, for example, utilizing rename to molecularly supplant the substance of a record. Lamentably, more perplexing operations, for example, programming establishment or redesign, can't be consolidated into a solitary framework call. An inadequate programming introduce can leave the framework in an unusable state. Executing the whole programming introduce molecularly and in disconnection would be a capable instrument for the framework manager, yet no standard working framework gives a blend of framework deliberations that can express it. In the vicinity of simultaneousness, applications must guarantee consistency by confining a progression of alterations to vital information from obstruction by different assignments.(Donald E. Watchman and Emmett Witchel)
An essential worry of a multiuser database administration framework is the way to control simultaneousness, which is the concurrent access of the same information by numerous clients. Without sufficient simultaneousness controls, information could be overhauled or changed shamefully, trading off information trustworthiness. One approach to oversee information simultaneousness is to make every client sit tight for a turn. The objective of a database administration framework is to lessen that hold up so it is either nonexistent or immaterial to every client. All information control dialect proclamations ought to continue with as meager impedance as would be prudent, and ruinous cooperations between simultaneous exchanges must be averted. Dangerous cooperation is any collaboration that inaccurately overhauls information or erroneously changes basic information structures. Neither execution nor information trustworthiness can be relinquished. Prophet determines such problems by utilizing different sorts of locks and a multiversion constancy model. These elements depend on the idea of an exchange.
Perused Consistency
Perused Consistency, Undo Records, and Transactions
Prophet utilizes current data as a part of the framework worldwide zone and data in the fix records to develop a read-reliable perspective of a table's information for an inquiry. Just when an exchange is submitted are the progressions of the exchange made changeless. Articulations that begin after the client's exchange is submitted just see the progressions made by the conferred exchange. The exchange is vital to Oracle's procedure for giving read consistency. This unit of conferred SQL articulations:
Here is program for sorting using thread...
import java.util.ArrayList;
import java.util.List;
public class ThreadedMergeSorter<E extends Comparable<? super E>> implements, Runnable
{
private List<E> list;
private List<E> left, right;
private Thread t1, t2;
private static final int maxThreads = 4;
private static AtomicInteger currentThreads = new AtomicInteger(0);
private ThreadedMergeSorter(List<E> list)
{
this.list = list;
}
public ThreadedMergeSorter(){}
public void sort(List<E> list)
{
if(list.size() > 1)
{
left = new ArrayList<E>(list.subList(0, list.size()/2));
right = new ArrayList<E>(list.subList(list.size()/2, list.size()));
list.clear();
if(currentThreads.get() < maxThreads)
{
t1 = new Thread(new ThreadedMergeSorter<E>(left));
t1.start();
currentThreads.incrementAndGet();
}
else sort(left);
if(currentThreads.get() < maxThreads)
{
t2 = new Thread(new ThreadedMergeSorter<E>(right));
t2.start();
currentThreads.incrementAndGet();
}
else sort(right);
try{
if(t1 != null)
{
t1.join();
currentThreads.decrementAndGet();
}
if(t2 != null)
{
t2.join();
currentThreads.decrementAndGet();
}
}catch(InterruptedException e){}
list.addAll(mergeSortedLists(left, right));
}
}
private List<E> mergeSortedLists(List<E> leftList, List<E> rightList)
{
ArrayList<E> list = new ArrayList<E>();
while(!leftList.isEmpty() && !rightList.isEmpty())
{
if((leftList.get(0)).compareTo(rightList.get(0)) <= 0)
list.add(leftList.remove(0));
else
list.add(rightList.remove(0));
}
if(!leftList.isEmpty())
list.addAll(leftList);
if(!rightList.isEmpty())
list.addAll(rightList);
return list;
}
@Override
public void run()
{
sort(this.list);
}
}
The problem is in the sort(List<E> list) method by the if statements and the try catch block.
Solution:
First off, I am not running anything in parallel. Threads are started with start(), not run(), which simply calls the run method on the current thread.
Second, if I have shared variables being updated, try to declare them as AtomicInteger like :
private static AtomicInteger currentThreads = new AtomicInteger(0);
Then use these methods to atomically increment/decrement:
currentThreads.incrementAndGet();
currentThreads.decrementAndGet();
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.