スキップしてメイン コンテンツに移動

投稿

ラベル(Serialization)が付いた投稿を表示しています

Google App Engine Task Queue - Using DeferredTask

When to Use Google App Engine Task Queue? You should use task queue when you try to do something taking time such as storing or updating bunch of data to datastore. In Google App Engine, a http request which isn't returned by timeout should be simply failed. The timeout configured on Google App Engine is 60 seconds. Please see https://developers.google.com/appengine/articles/deadlineexceedederrors . So in order to response back to the client quickly, you should use Task Queue for tasks which takes long time. Push Tasks to Task Queue I have read an official document of Task Queue and tried to use it. What frustrates me is the document only explains how to create a task with parameters, push the task to the task queue and pass to the worker servlet. i.e. actual heavy part is treated in the worker servlet. Of course it is fine, but I felt it was a bit indirect way to push tasks to queue. What I desired to do is creating task object and pushing it to the queue in one single

Encode Java Object to XML and Decode XML to Java Object

In current software development world, serializing object to some human readable format such as "XML", "JSON" is quite common. In this post I will show you a small code snippet for encoding Java Object to XML and decoding XML to Java Object only using Java Standard API. I think this approach is suitable if you need to quick and simple solution to encoding and decoding java object to XML string. Actually code is very simple. Please see the code below :) If you need to input or output XML to file, you should pass FileOutputStream or FileInputStream instead of ByteArrayOutputStream or ByteArrayInputStream. package com.dukesoftware.utils.xml; import java.beans.XMLDecoder; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; public class XMLUtils { public final static Object decodeToXML(String file) throws FileNotFoundException{ try(XMLDecoder decoder =

Java Customize Serialization - Using Externalizable

I will show you how to customize Java serialization (Externalization), performance comparison default serialization vs my externalization implmentation in this post. In the most cases, you don't have to care about the serialization performance of default implementation. But the default implementation uses reflection so it might be a problem if you develop performance critical application. Externalizable Implement your own serialization is very simple. Just implements Externailizable interface into the class. Here is the example code - simple pojo class and TreeMap which implements Externalizable. package com.dukesoftware.demos.externalizable; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.util.ArrayList; import java.util.List; public class ExternalizableClass implements Externalizable{ private String field1; private Double field2; private List<String> field3; public S