So the Windows 8 Upgrade Assistant tells me that I cannot use Office 2003:
Well I upgraded my Windows 7 to Windows 8 (that is I did NOT perform a clean install). And how does for example Word 2003 work:
Well it turns out that it works just fine! I haven't tried every feature, but everything I have tried appears to work. That includes Excel 2003 and Visio 2003.
Lennart Schedin
A software developer from Sweden
29 January 2013
17 January 2013
The Eclipse foreach template
There are many "hidden" features in Eclipse that are really good. Today I discovered the foreach template.
It works like this: place your cursor just above a array or Iterable (List) declaration. Press Ctrl + Space and press Enter. Eclipse will now create a for loop that you can use. It will use the Iterable variable that is closest.
Before:

After:
It works like this: place your cursor just above a array or Iterable (List) declaration. Press Ctrl + Space and press Enter. Eclipse will now create a for loop that you can use. It will use the Iterable variable that is closest.
Before:

After:
27 June 2012
The ++ operator is not thread safe
Findbugs is great tools for analyzing java code. It can find potential bugs. One of the warnings is the VO: An increment to a volatile field isn't atomic (VO_VOLATILE_INCREMENT). It means that the ++ operator is not an atomic operation and thus not thread safe. To demonstrate this looks at this code:
To fix this you could add a synchronized block, but a better approach is to use an AtomicInteger like this:
public class PlusPlusOperatorThreadSaftey {
@Test
public void testThreadSaftey() throws InterruptedException {
class IntegerHolder {
private volatile int value = 0;
private void increase() {
value++;
}
private int getValue() {
return value;
}
}
final IntegerHolder integerHolder = new IntegerHolder();
final int numberOfIncreasePerThread = 50;
final int numberOfThreads = 100;
ExecutorService threadPool = Executors.newFixedThreadPool(numberOfThreads);
for (int i = 0; i < numberOfThreads; i++) {
threadPool.submit(new Runnable() {
public void run() {
for (int i = 0; i < numberOfIncreasePerThread; i++) {
integerHolder.increase();
}
}
});
}
threadPool.shutdown();
threadPool.awaitTermination(10, TimeUnit.SECONDS);
assertEquals(integerHolder.getValue(), numberOfIncreasePerThread *
numberOfThreads);
}
}
When running this code on my dual core CPU sometimes the test case passes, and sometimes I get:java.lang.AssertionError: expected:<4998> but was:<5000>. Thus, the ++ operator is not atomic and updates can be lost.To fix this you could add a synchronized block, but a better approach is to use an AtomicInteger like this:
class IntegerHolder {
private AtomicInteger value = new AtomicInteger(0);
private void increase() {
value.incrementAndGet();
}
private int getValue() {
return value.get();
}
}
11 June 2012
Create named "screen"s to continue work later
The Unix command screen is a great command that lets you manage your login sessions. If you for some reasons shares an account with several people or have many different contexts it is useful to crate a named screen session:
To list all the screens use:
To attach to a named screen:
lennart@pingvinen:~$ screen -S myScreen
To list all the screens use:
lennart@pingvinen:~$ screen -list
There are screens on:
14825.myScreen (2012-06-11 08.15.28) (Attached)
14692.pts-0.pingvinen (2012-06-11 08.13.25) (Detached)
2 Sockets in /var/run/screen/S-lennart.
Note that one of the screens are named (the myScreen) and one is unnamed and gets a default name.To attach to a named screen:
lennart@pingvinen:~$ screen -r myScreen
16 April 2012
Increase of Linux IO scheduler queue size might lower performance
The blog post Linux I/O scheduler queue size and MyISAM performance explains a good way to increase performance when using Mysql and the Myisam database table engine. I have tried this an can confirm that it will increase performance for this typical application.
I have unfortunately discovered that it may not always increase the overall performance if you have other IO intensive operations besides an Mysql database running on your server. I have a system that runs both Mysql with Myisam and also a custom written database application that uses a lot (like 10000) small files to save data.
The system handles a stream of "messages". I measure performance by looking at graphs of how many messages are buffered (0 to 100000) and how many messages that has been discarded because the buffer is full.
For nr_requests = 128
For nr_requests = 10000
As seen from the graphs the configuration with default nr_requests (128) performs better. My advice is thus to benchmark if your specific application benefits an increased queue size.
I have unfortunately discovered that it may not always increase the overall performance if you have other IO intensive operations besides an Mysql database running on your server. I have a system that runs both Mysql with Myisam and also a custom written database application that uses a lot (like 10000) small files to save data.
The system handles a stream of "messages". I measure performance by looking at graphs of how many messages are buffered (0 to 100000) and how many messages that has been discarded because the buffer is full.
For nr_requests = 128
For nr_requests = 10000
As seen from the graphs the configuration with default nr_requests (128) performs better. My advice is thus to benchmark if your specific application benefits an increased queue size.
09 April 2012
A free ssh client for Ipad
There are a bunch of ssh clients in Apple App Store that costs money. If your looking for a free one for Ipad the number is reduced: a search for the "ssh" and Price = "Free" yields 9 hits. Out of these 9 only 2 is and actual ssh client: zatelnet and Rove Mobile Admin Client.
Out of curiosity I tried Rove Mobile Admin Client. It's main purpose is actually not to be an ssh client, but to be a remote management tool for their commercial server software. But that doesn't matter, since the ssh client part of the app is free to use standalone. I could successfully connect to my home Linux computer:
Don't expect miracles out of this app, since it is free it is probably a lot worse than some "real" non-free ssh clients. But you can do basic things.
Pros:
- Can use private key for authentication
- Can edit files in nano (requires rather good terminal emulation and the abilities to send Ctrl sequences).
- Does maintain connection when you switch to another app
- Does not support UTF-8 (since Ubuntu uses this as default it can be a bit frustrating)
- Does not support select, copy and paste in the terminal emulation.
- Very slow (the time for a key press to "echo" is in the magnitude of 1 s).
- Can only have one open connection at a time
A side note: the app also includes an RDP client, but forget about using it, it is painfully slow.
27 March 2012
Me against the world: Singleton?
I just looked at http://www.reddit.com/r/java/comments/qpb8p/java_ee_revisits_the_design_patterns_singleton/. I find it rather interesting that the comments against Singleton have low scores and comments in favor have high scores.
This leads me to think: is it me against the world? Well at least my kind of programmer - that thinks that Singleton is a code smell - is in minority? Just to boost "my" side of argumentation let me be clear:
Don't us Singleton(s)!
I have personally had firsthand experience of inheriting a code base where Singletons was used extensively. It's a total nightmare! For me two areas stand out:
This leads me to think: is it me against the world? Well at least my kind of programmer - that thinks that Singleton is a code smell - is in minority? Just to boost "my" side of argumentation let me be clear:
Don't us Singleton(s)!
I have personally had firsthand experience of inheriting a code base where Singletons was used extensively. It's a total nightmare! For me two areas stand out:
- Writing test code for Singleton is much harder. You always have to watch out if one part of the code makes a side effect that makes your test case either false positive or false negative.
- Converting a single threaded system into a multi threaded system just does not work with Singleton. You basically have to remove everything for it to work well and to avoid unnecessary synchronizations.
Subscribe to:
Posts (Atom)



