Синхронизация между двумя базами данных

Я получаю NoClassFoundError, когда классы, загруженные загрузчиком классов среды выполнения, не могут получить доступ к классам, уже загруженным загрузчиком Java. Поскольку разные загрузчики классов находятся в разных доменах безопасности (согласно java), jvm не позволит разрешать классы, уже загруженные корневым загрузчиком, в адресном пространстве загрузчика времени выполнения.

Запустите вашу программу с помощью 'java -javaagent: tracer.jar [YOUR java ARGS]'

Она выводит вывод загруженного класса и загрузчика env, который загрузил класс. Очень полезно отслеживать, почему класс не может быть решен.

// ClassLoaderTracer.java
// From: https://blogs.oracle.com/sundararajan/entry/tracing_class_loading_1_5

import java.lang.instrument.*;
import java.security.*;

// manifest.mf
// Premain-Class: ClassLoadTracer

// jar -cvfm tracer.jar manifest.mf ClassLoaderTracer.class

// java -javaagent:tracer.jar  [...]

public class ClassLoadTracer 
{
    public static void premain(String agentArgs, Instrumentation inst) 
    {
        final java.io.PrintStream out = System.out;
        inst.addTransformer(new ClassFileTransformer() {
            public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {

                String pd = (null == protectionDomain) ? "null" : protectionDomain.getCodeSource().toString();
                out.println(className + " loaded by " + loader + " at " + new java.util.Date() + " in " + pd);

                // dump stack trace of the thread loading class 
                Thread.dumpStack();

                // we just want the original .class bytes to be loaded!
                // we are not instrumenting it...
                return null;
            }
        });
    }
}
6
задан Jonas 19 December 2011 в 03:41
поделиться

1 ответ

Do you mean you need to be able to work via the web application even when offline? Sounds like you need Google Gears or another HTML5 structured storage implementation.

If you using a native app when offline, then yes, it sounds like you'll want a local database for that too.

Do the users typically know when they're going to go offline? If so, you could let them "check out" the subset of the database they're going to need, then later "go online" and synchronize. Otherwise, you may want to synchronize data that they've used recently, but purge the local database of data they haven't used for a long time.

Quite how hard that will be will depend on your exact application. Do multiple users need to be able to work on the same set of records simultaneously, for example?

5
ответ дан 17 December 2019 в 04:50
поделиться
Другие вопросы по тегам:

Похожие вопросы: