Tuesday, 18 November 2008
Common Errors in C
Sunday, 2 November 2008
Java Workqueue API
- executors
- queues
- concurrent collections
- synchronizers
- atomic (in package: java.util.concurrent.atomic )
- locks (in package: java.util.concurrent.locks )
Executors
Executors are containers taking care of the execution of tasks, just as SwingUtilities used to do it. Different kinds of executors are imaginable:- DirectExecutor (performing the task but not asynchronously)
- ThreadPerTaskExecutor (one thread is created for each task to be performed)
- SerialExecutor (each task is performed sequentially)
- ThreadPoolExecutor (executor performing using a pool of threads)
- ScheduledThreadPoolExecutor (executor performing using a pool of threads at certain specified moments or periodically)
Queues
Another useful data structure for performing task in parallel and asynchronously are queues (also known as FIFO data structures). The java.util.concurrent package provides a number of data structures for this purpose too. One particular kind of FIFO are blocking queues, for which five different versions exist:- LinkedBlockingQueue
- ArrayBlockingQueue
- SynchronousQueue
- PriorityBlockingQueue
- DelayQueue
Synchronizers
A number of possible techniques can be used to synchronize threads. Among these are semaphores which we discussed in the linux kernel context. Other types provided by the java.util.concurrent package, such as the CountDownLatch, used to block some actions until a number of events or elements have been counted, the CyclicBarrier, which is a resettable multiway synchronization mechanism, an exchanger to allow threads to exchange objects at some definite point and the already mentioned locks.Concurrent Collections
The java.util Collection Framework already contained a number of snychronized or synchronizable classes. However, the java.util.concurrent package introduces new structures useful in a multithreaded context:- ConcurrentHashMap,
- ConcurrentSkipListMap,
- ConcurrentSkipListSet,
- CopyOnWriteArrayList, and
- CopyOnWriteArraySet
Timing Units
The java.util.concurrent package also introduces a new class TimingUnit to provide different kind of granularity as to which unit of interval for time measurements should be used. Here again, it would be useful to take a look at the implementation of the kernel and compare.Atomic and Locks
Since atomic variables and locks are in other packages, I will describe them in other entries. However, it is again interesting to note that the same topics were already discussed in other entries of this blog.Flash with Flex
So I tried a few things with Flash now that I more or less know the basics of flex (and only the basics).
So I wrote my first little movie in flash and compiled it using flex's compiler.
I can not really do an introduction yet to flash and flex. I still need to get use to too many things. For example, I am not really happy not knowing which data structures are available in action script. Maybe I have been spoiled by java using the java.util collections. Yet I think it sensible to expect the existence of a number of standard libraries one can use to prevent the inventingthewheelitis.
One thing I found at least im internet is from a developer from Mannheim who wrote some data structures for games in action script. I will have to take a look at it. It sure sounds really interesting.
I have also been interested in what is the best way to create small movies for fun. So I just thought of the general object oriented structure of my character creations. Actually I already had some project of the sort in java. But I had not that much because other priorities popped up as they always do.
Oprofile - What are thou ?
O.K Apart from doing stupid references to films I actually have not really liked. What am I doing?
After reading a few mails from the Linux Kernel Mailing list, I found the following tool which seems useful: oprofile. I must admit I still do not have a clear idea of all the possibilities that this tool offers.
The first thing to know it is a profiler and it is a profiler capable of giving a number of information on a program with quite a low overhead. But what is a profiler?
A profiler collects information on running processes of a computer to analyze the performance of a program (see the wikipedia article on performance analysis).
It gives the possibility to look at the following aspects of a system:
- Call-graphs (i.e it looks at the graph of the functions calls of programs)
- libraries used by a program
- instruction level information collections (also on assembly code level)
Saturday, 25 October 2008
Interesting Week
- network problems with TCP/UDP broadcast
- flash/flex sandbox security issues
Monday, 6 October 2008
Performance according to Martin Fowler
- response time
- responsiveness
- latency
- throughput
- the load
- load sensitivity
- efficiency
- capacity
- response time
- the time it take to a system to process a request
- responsiveness
- the time that the system takes to acknowledge a request
- latency
- the minimum time that the system needs to perform any task even if the task has nothing to be done
- throughput
- how much work can be done in a given amount of time
- load
- how much strain are put on the resources (for example how many users ( or processes ) are logged on (or running)
- load sensitivity
- an indicator of the variation in the response time depending on the load
- efficiency
- the efficiency is the performance (i.e, either throughput or response time) divided by resources
- capacity
- indicate the maximum effective throughput or load for the system
Thursday, 2 October 2008
What's the ack is that ?
Well! as I was looking at the programs I was updating on my fedora 9 box. I fell upon the program ack. I had no idea what it was so I ran rpm -qi ack... And it told me that it was a kind of grep replacement. It seems to be faster than grep in most cases. Some people tried it out it seems. Though some other seem to disagree.
One of the advantage of ack is that it allows to select more easily the type of files to be checked. So I guess I will have to take a look at it....
Monday, 29 September 2008
Some Ideas for Desktop Improvements
To Do List
I want a to do list which is more or less always present when the desktop is on.- classification by priorities
- important and urgent
- not important but urgent
- important and not urgent
- not important and not urgent
- not classified
- classification by subject
- work
- administrativ
- Hobby
- Family
- Style of the task and Icons
- Position of Tasks as Desktop Icons
- Size of Desktop Icons
Organized Important Files
I want that the files which I have on my desktop are organized in a meaningful way, for example in thematic and time oriented way. From left to right time oriented, top to bottom thematic. Of course the classification cannot be automatic for the thematic way. Moreover, the time oriented way might not always be relevant.Friday, 26 September 2008
Firefox Plugins
- No Script
- an add on to control easily whether scripts (java, javascript, flash) are allowed to be performed. This is a per domain enabling or not.
- Download Them All
- with this add on, it easier to download many resources from a web page
- Download Status Bar
- adds a status bar which shows the status of downloading of things from firefox.
- Greasemonkey
- using greasemonkey allows to write scripts to be performed on top of web pages
- Firebug
- This is a utility to help in developing javascripts.
Monday, 22 September 2008
Hibernate
Second Edition of Hibernate in Action
Christian Bauer and Gavin King
November, 2006 | 880 pages
ISBN: 1-932394-88-5
The goal is to map the objects created by a object programming language such as Java to a relational database in order to provide persistent objects, i.e object which can be stored on disk and which do not disappear when the virtual machine shutdowns. Hibernate performs the mapping using configurations files in xml (or other). Here is an example of XML file for a mapping called tasks.hbm.xml:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
name="mytasks.Task"
table="TASKS">
<id
name="id"
column="TASK_NAME">
<generator class="increment"/>
</id>
<property
name="name"
column="Task_NAME"/>
<many-to-one
name="nexttask"
cascade="all"
column="SPOUSE_ID"
foreign-key="FK_NEXT_TASK"/>
</class>
</hibernate-mapping>
private String name;
private Task nexttask;
}
import persistence.*;
import java.util.*;
public class TaskExample {
public static void main(String[] args) {
// First unit of work
Session session =
HibernateUtil.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
Task firsttask = new Task("Learn Hibernate");
Long meberId = (Long) session.save(firsttask);
tx.commit();
session.close();
// Second unit of work
Session newSession = HibernateUtil.getSessionFactory().openSession();
Transaction newTransaction = newSession.beginTransaction();
List tasks = newSession.createQuery("from Task m order by m.name asc").list();
System.out.println( tasks.size() + " Task(s) found:" );
for ( Iterator iter = members.iterator(); iter.hasNext(); ) {
Tasks task = (Task) iter.next();
System.out.println( task.getName() );
}
newTransaction.commit();
newSession.close();
// Shutting down the application
HibernateUtil.shutdown();
}
}
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">
org.postgresql.Driver </property>
<property name="hibernate.connection.url">
jdbc:postgresqll://localhost
</property>
<property name="hibernate.connection.username">
sa
</property>
<property name="hibernate.dialect">
org.hibernate.dialect.HSQLDialect
</property>
<!-- Use the C3P0 connection pool provider -->
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<!-- Show and print nice SQL on stdout -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<!-- List of XML mapping files -->
<mapping resource="mytasks/tasks.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Note the use of a certain number of configuration entries:
- the Hibernate connection pool provider: here the C3PO-connection-pool-provider
- the hibernate dialect used, here the HSQLDialect
- the connection information: drivers, url and username
- the mapping file
There are a number of other possibilities to configure Hibernate.