lmaxjava的简单介绍

博主:adminadmin 2022-12-27 15:54:08 61

今天给各位分享lmaxjava的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java事件驱动框架有哪些推荐

LMAX架构,所谓LMAX,是一种新型零售金融交易平台,它能够以很低的延迟(latency)产生大量交易(吞吐量). 这个系统是建立在JVM平台上,核心是一个业务逻辑处理器,它能够在一个线程里每秒处理6百万订单. 业务逻辑处理器完全是运行在内存中(in-memory),使用事件源驱动方式(event sourcing). 业务逻辑处理器的核心是Disruptors,这是一个并发组件,能够在无锁的情况下实现网络的Queue并发操作。他们的研究表明,现在的所谓高性能研究方向似乎和现代CPU设计是相左的

java 并发框 架有 disruptor实例

LongEvent.java

public class LongEvent

{

    private long value;

    public void set(long value)

    {

        this.value = value;

    }

}

LongEventFactory.java

import com.lmax.disruptor.EventFactory;

public class LongEventFactory implements EventFactoryLongEvent

{

    public static final LongEventFactory INSTANCE = new LongEventFactory();

    public LongEvent newInstance()

    {

        return new LongEvent();

    }

}

LongEventHandler.java

import com.lmax.disruptor.EventHandler;

public class LongEventHandler implements EventHandlerLongEvent

{

    public void onEvent(LongEvent event, long sequence, boolean endOfBatch)

    {

        System.out.println("Event: " + event);

    }

}

LongEventProducer.java

import java.nio.ByteBuffer;

import com.lmax.disruptor.RingBuffer;

public class LongEventProducer

{

    private final RingBufferLongEvent ringBuffer;

    public LongEventProducer(RingBufferLongEvent ringBuffer)

    {

        this.ringBuffer = ringBuffer;

    }

    public void onData(ByteBuffer bb)

    {

        long sequence = ringBuffer.next();  // Grab the next sequence

        try

        {

            LongEvent event = ringBuffer.get(sequence); // Get the entry in the Disruptor

                                                        // for the sequence

            event.set(bb.getLong(0));  // Fill with data

        }

        finally

        {

            ringBuffer.publish(sequence);

        }

    }

}

LongEventMain.java

import java.nio.ByteBuffer;

import java.util.concurrent.Executor;

import java.util.concurrent.Executors;

import com.lmax.disruptor.RingBuffer;

import com.lmax.disruptor.dsl.Disruptor;

public class LongEventMain

{

    public static void main(String[] args) throws Exception

    {

        // Executor that will be used to construct new threads for consumers

        Executor executor = Executors.newCachedThreadPool();

        // The factory for the event

        LongEventFactory factory = new LongEventFactory();

        // Specify the size of the ring buffer, must be power of 2.

        int bufferSize = 1024;

        // Construct the Disruptor

        DisruptorLongEvent disruptor = new Disruptor(factory, bufferSize, executor);

        disruptor.handleEventsWith(new LongEventHandler());

        // Start the Disruptor, starts all threads running

        disruptor.start();

        // Get the ring buffer from the Disruptor to be used for publishing.

        RingBufferLongEvent ringBuffer = disruptor.getRingBuffer();

        LongEventProducer producer = new LongEventProducer(ringBuffer);

        ByteBuffer bb = ByteBuffer.allocate(8);

        for (long l = 0; true; l++)

        {

            bb.putLong(0, l);

            producer.onData(bb);

            Thread.sleep(1000);

        }

    }

}

java中归并排序

1、归并排序实现:

  

public static void main(String[] args) {

int a[]={1,8,2,6,5,4};

int[] arr= sort(a,0,a.length-1);

for(int rr=0;rr=5;rr++)

System.out.printf("%d\t", arr[rr]);

System.out.printf("\n");

}

public static int[] sort(int[] a,int low,int high){

    int mid = (low+high)/2;

    if(lowhigh){

        sort(a,low,mid);

        sort(a,mid+1,high);

        //左右归并

        merge(a,low,mid,high);

    }

    return a;

}

 

public static void merge(int[] a, int low, int mid, int high) {

    int[] temp = new int[high-low+1];

    int i= low;

    int j = mid+1;

    int k=0;

    // 把较小的数先移到新数组中

    while(i=mid  j=high){

        if(a[i]a[j]){

            temp[k++] = a[i++];

        }else{

            temp[k++] = a[j++];

        }

    }

    // 把左边剩余的数移入数组 

    while(i=mid){

        temp[k++] = a[i++];

    }

    // 把右边边剩余的数移入数组

    while(j=high){

        temp[k++] = a[j++];

    }

    // 把新数组中的数覆盖nums数组

    for(int x=0;xtemp.length;x++){

        a[x+low] = temp[x];

    }

}

2、简单的数组排序

public static void main(String[] args) {

int a[]={1,8,2,6,5,4};

Arrays.sort(a);

for(int rr=0;rr=5;rr++)

System.out.printf("%d\t", a[rr]);

System.out.printf("\n");

}

java中int型最大值是多少

在计算机中他是从0000 0000 0000 0000~0111 1111 1111 1111(正数),0000 0000 0000 0000~1111 1111 1111 1111(负数)一共16个

第一位是符号位,后面的是数值位!

其中不同的机器,int在存储器中的大小也不一样,如果是32位机上他是4位的,和float的整数部分一样,也就是说是现在的2的16次方倍,那就更大了,你说的32767是16位机上的,这也和编译软件有关,在turboc C2.0上是2位,turboc C 3.0就是4位,是具体参照编译软件!当然这也可以设置的!!

java中int型最大值是多少?

int max=2147483647

int min=-2147483648

代码片段:

byte bmax, bmin;

short shmax, shmin;

char cmax, cmin;

int imax, imin;

long lmax,lmin;

float fmax,fmin;

double dmax,dmin;

fmax = Float.MAX_VALUE;

fmin = Float.MIN_VALUE;

dmax = Double.MAX_VALUE;

dmin = Double.MIN_VALUE;

bmax = Byte.MAX_VALUE;

bmin = Byte.MIN_VALUE;

cmax = Character.MAX_VALUE;

cmin = Character.MIN_VALUE;

shmax = Short.MAX_VALUE;

shmin = Short.MIN_VALUE;

imax = Integer.MAX_VALUE;

imin = Integer.MIN_VALUE;

lmax = Long.MAX_VALUE;

lmin = Long.MIN_VALUE;

System.out.println("float max="+fmax);

System.out.println("float min="+fmin);

System.out.println("double max="+dmax);

System.out.println("double max="+dmin);

System.out.println("byte max="+bmax);

System.out.println("byte min="+bmin);

System.out.println("char max="+cmax);

System.out.println("char min="+cmin);

System.out.println("short max="+shmax);

System.out.println("short min="+shmin);

System.out.println("int max="+imax);

System.out.println("int min="+imin);

System.out.println("long max="+lmax);

System.out.println("long min="+lmin);

输出:

float max=3.4028235E38

float min=1.4E-45

double max=1.7976931348623157E308

double max=4.9E-324

byte max=127

byte min=-128

char max=?

char min=

short max=32767

short min=-32768

int max=2147483647

int min=-2147483648

long max=9223372036854775807

long min=-9223372036854775808

说明:

实际上是每种类型的Container类定义的常量。

lmaxjava的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、lmaxjava的信息别忘了在本站进行查找喔。

The End

发布于:2022-12-27,除非注明,否则均为首码项目网原创文章,转载请注明出处。