java

The solution to the problem is that we changed the database model so that we got rid of the circular references. Then we had no problems loading all the data

Performance monitoring of a cloud deployment

An application go-live took a wrong turn - a dozen of connected clients took a cloud system down, that should cope with thousands of them. As I was assigned to analyze the problems I discovered that this is a composite problem created by (amongst other things) careless usage of Hibernate (an ORM framework for easier, vendor-agnostic database access) and way to much complex logic built 'into' the database - killing both the database and the web applications host by using up its CPU. After using Hibernate statistics for analyzing the transactions that are being sent to the database, I started by rewriting some SQL queries that didn’t perform well. Some complex Java/Hibernate logic even had a kind of memory leak in it which could be resolved by writing a single database stored procedure. A connectivity checking method for the clients was moved from saving ping data in the database to an efficient in memory solution using an in-memory data grid called Hazelcast. Nevertheless the CPU load stayed above an acceptable threshold. Using an application performance management tool I could find another root cause in a flawed function that was being called periodically. Looking at the CPU load graph one could see that the CPU went about each three minutes from under 10 to almost 100 percent. The load was created by one single thread with about 80% of network IO and 20% code execution, where multiple database calls were made, responses sorted and analized. Not only was the sorting flawed, also the database calls were being performed for all rows in one table and not just for a small subset of the entries. After a rewrite the CPU usage dropped to a single-digit percentage which kept the system in a healthy state.

A method to mock a new instance in the class is using the powermockito. Powermockito has a function whenNew. This one can be used to solve this kind of problem.

Following are the characters of the OOP:
1. Encapsulation: capturing and keeping data safely and securely from outside interfaces.
2. Inheritance: class can be derived from a base class, and contains all the feature of the base class but it still has some of its own features.
3. Polymorphism: The ability of objects of different types to respond to functions of the same name.
4. Abstraction: representing the data at a very conceptual level without any details.

Make use of a time-based scheduler Cron, which is available on Debian (as well as on other Unix-like operating systems). Quartz offers a seamless integration with Java applications. Scheduling a particular script (e.g. restarting server) can be easily done using Cron expressions in form of a string consisting of five or six fields (separated by white space), which are respectively responsible for: minutes, hours, day of month, month, day of week, year.

1) Implement a procedure to restart server (e.g. integrated in Java application or through system script).
2) Make use of Quartz to provide Cron functionality to Java application, in particular to make use of Cron expressions.
3) Provide an option for (privileged/administrator) users to manage Cron expression string for restarting server in web interface.
4) Explain in a short summary the principle of functioning of Cron expressions, providing examples of the most common usages.

Update environment variable

Indeed the environment variable on windows does not get updated automatically. So you have to adjust the variable, for a windows computer with german language settings, in: System -> Erweiterte Systemeinstellungen -> Umgebungsvariablen...
Now you only have to update the "JAVA_HOME" variable with the concrete path and/or version number.

Taggings:

Adding components to the Apache Camel main class

The main issue is that Camels main class does not handle its context appropriately. Although its method .getOrCreateCamelContext() returns a context and allows you to add the desired component, the context may not be as unique as one thinks when reading the corresponding description. Furthermore, when it comes to the execution of the code (main.run()), a post-processing method tends to override the created context with an empty one. To still be able to work with Camel and pure Java DSL, you can create a new main class as an extension of Camels main. Within this new class you start introducing your own instance of CamelContext and handle it in an uniquely manner. To do so the methods .getOrCreateCamelContext() and .postProcessContext() have to be overridden as shown within the provided code snippet.

Add Hystrix

Hystrix (https://github.com/Netflix/Hystrix) is a fault tolerance library developed by Netflix, which uses the circuit breaker pattern to increase the fault tolerance of your Java code. It works by wrapping your code in so called Commands and providing Fallback Methods.

It is integrated in spring cloud, with the spring-cloud-starter-hystrix maven artifact.

The spring integration allows you to declare your service methods as Hystrix commands with annotations, for example:

@HystrixCommand(fallbackMethod = "fallback", commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = TIMEOUT)
})
public Object callService() {
//insert code to send a request to one of your microservices, which could fail, here
}

private Object fallback(){
//insert code to execute if service fails or takes too long to answer here
}

With above code snippet you can declare a time out for your method, after which the fallback method will be executed. Furthermore the fallback method is executed should an exception occur or if the method failed too often consecutively (circuit breaker pattern). This allows for fail fast semantics and the failing/overwhelmed microservice you are trying to call is given time to recover.

Using RunOnUiThread to see user interface changes in Xamarin

If you are in your own thread and the code looks similar to this:

//1. Code before your UI action

//2. Code that changes UI

//3. Code after your UI action

Than you need to do the following.

First you need to get the current instance of you main activity that you are in, this can be achieved like this:
In your MainActivity.cs you need to change the App loading to
// LoadApplication(new App(this));

In your "App" class you than write:
// public App(Object o)
and
// currentMainActivity = (Android.App.Activity)o;

After that you have everywhere in your code access to the current java main activity.
To do some UI actions in your threads, just use the following code:

//1. Code before your UI action

App.currentMainActivity.RunOnUiThread(() =>
{
// 2. Code that changes UI
});

//3. Code after your UI action

Taggings:

Preventing multiply output lines in Xamarin for Visual Studio on Android developement

I have used an very easy solution for this problem.
Whenever I need to do some output to the console (hint: you should only do this for you own purpose, later on you should Logging with respective logging levels in you app!) I do it the following way:

In the "App" class i have created a new method called "WriteLine" and there I use a dependency service call to execute some native java code on the android device:

public static void WriteLine(String line)
{
DependencyService.Get().WriteLine(line);
}

If you need help for using the DependencyService please look into further tutorials on that!
In the Implementation of the interface IOutput you just need the following code:

public void WriteLine(string line)
{
Console.WriteLine(line);
}

Like this you use the java "Console" class and you get the output at least one time less.

Taggings:

Pages

Subscribe to java